Validation Rules

When adden the "on" paramater to some of my validation rules, the validation doesnt work as it should.

part of the code:




//part of User Model

public function rules(){

	return array(

		array('email, password', 'required', 'on' => 'login'),

		array('password', 'compare', 'compareValue' => 'passwordCheck', 'on' => 'install'),

		array('password', 'authenticatePass', 'on' => 'login'),

		array('name, email', 'length', 'max' => 128),

		array('email', 'email'),

	);

}

public function authenticatePass($attribute, $params) {

	echo "Start AuthenticatePass";

}



Now when i do the following:




$user = new User();

$user->attributes = $_POST['user'];

$user->validate('login');



$user->validate(‘login’) always returns true. And “Start AuthenticatePass” is echoed nowhere.

Am I missing something? Or is this an error in the 1.1alpha…

Found the solution… what I was looking for is called "scenario", that made the searching through code a bit easier ^^.




$user = new User('login');

$user->attributes = $_POST['user'];

$user->validate();



Is the right way to use scenarios in 1.1

It was also deprecated in previous versions. The preferred way is to call setScenario (or by assigning value to scenario property as expected in Yii).