Oct 18 2008

Unique validation rule in CakePHP 1.2

Category: CakePHP, PHPvbmendes @ 08:46

In this post I will show an example of how apply the unique validation rule in CakePHP 1.2. It’s very important to do in some cases, like saving users. You must make sure that the username is unique in your system. Lets see how it works:

var $validate = array(
	'username' => array(
		'rule' => array('isUnique'),
		'message' => 'Username already in use.'
	)
);

I wrote a custom function to validate it, but thanks to Dia now I know the built-in validation rule.

Tags: , , ,

3 Responses to “Unique validation rule in CakePHP 1.2”

  1. Dia says:

    CakePHP 1.2 has a built-in unique validation rule :

    var $validate = array(
    ‘myField’ => array(
    ‘rule’ => ‘isUnique’,
    ‘message’ => ‘data already exists’
    ));

  2. vbmendes says:

    Thanks for the information, I didn’t see this rule. But I already fixed the post to use it. It’s better then custom functions.

  3. matheus says:

    it´s a super code!

    onde eu posso pegar a “tag cloud”? muito bem sacada…

    pode mandar pro email.

    até mais pessoal. congratulations!

Leave a Reply