Is there any one know what should I do so that users are required to fill in the input in request page only but not in create/update page? I had my own reason I want to do like that.
In User Model
array('user_email, user_name', 'required','on'=>'request'), //I want this only occur when on my request page
In User Controller
public function actionRequest()
{
$id=Yii::app()->user->uid;
$model=$this->loadModel($id);
if(isset($_POST['User']))
{
$model->attributes=$_POST['User'];
if ($model->validate('request'))
{
if($model->save())
{
$this->redirect(array('view','id'=>$uid));
}
}
}
$this->render('request',array(
'model'=>$model,
));
}
But somehow this does not work.
You will have to create your model with the
scenarioso that the rules applicable to thatscenariocan be applied.Let’s say your
scenarioissome_scenario, then when you declare therulesuse like so:Now to apply a scenario to a model we have to create that model instance with that scenario, like so:
Here’s a yii wiki that you might want to read.
Edit: In your case you can set the
scenarioafter the model object is created, by directly setting thescenarioproperty: