validate rule by action

Hi there,

I’m newbie of Yii.

I would like to validate the filed by action.

model


public function rules()

	{

		// NOTE: you should only define rules for those attributes that

		// will receive user inputs.

		return array(

			array('department_id' , 'required', 'on'=>'createsection', 'message'=>'Please select a department'),

			array('department_id' , 'required', 'on'=>'updatesection', 'message'=>'Please select a department')			

);

	}



controller


public function actionCreatesection()

	{

		$model=new Department;

.......

}


public function actionUpdatesection($id)

	{

		$model=$this->loadModel($id);

......

}

when I call the action, the validator are not validate. How should I validate the field by action?

Regards

Thu Ra

‘on’ refers to models scenario, not action…

use this instead:




public function actionCreatesection()

        {

                $model=new Department;

                $model->scenario = 'createsection';

.......

}


public function actionUpdatesection($id)

        {

                $model=$this->loadModel($id);

                $model->scenario = 'updatesection';

......

}



Thank you alot