Yii Framework Forum: Validation Rules - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Validation Rules " 'on' => 'task' " not working as it shoul Rate Topic: -----

#1 User is offline   RuudBurger 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 26
  • Joined: 23-February 09

Posted 25 August 2009 - 09:06 AM

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..
0

#2 User is offline   RuudBurger 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 26
  • Joined: 23-February 09

Posted 25 August 2009 - 09:38 AM

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
0

#3 User is offline   pestaa 

  • past Yii dev member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 705
  • Joined: 07-May 09
  • Location:Hungary

Posted 25 August 2009 - 11:51 AM

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).
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users