I am having the following form
<?php $form = $this->beginWidget('CActiveForm', array( 'id'=>'change-password', 'enableAjaxValidation'=>true, 'enableClientValidation'=>true, 'focus'=>array($model,'old-password') )); ?> <div class="row"> <?php echo $form->labelEx($model,'oldPassword'); ?> <?php echo $form->passwordField($model,'oldPassword'); ?> <?php echo $form->error($model,'oldPassword'); ?> </div> <div class="row"> <?php echo CHtml::submitButton('Submit'); ?> </div> <?php $this->endWidget(); ?>
The above form throws an error as
Fatal error: Call to a member function isAttributeRequired() on a non-object in /framework/web/helpers/CHtml.php on line 1414
I am new you yii framework so i am unable to guess where the error is. can anyone help
Edit 1
public static function activeLabelEx($model,$attribute,$htmlOptions=array()) { $realAttribute=$attribute; self::resolveName($model,$attribute); // strip off square brackets if any $htmlOptions['required']=$model->isAttributeRequired($attribute); return self::activeLabel($model,$realAttribute,$htmlOptions); }
Edit-2
If remove <?php echo $form->labelEx($model,'oldPassword'); ?>
am getting error as
Fatal error: Call to a member function getValidators() on a non-object in CHtml.php on line 2236
Advertisement
Answer
The $model variable does not contain a Model object, check if you you pass the correct object in render function.
ex for the create page:
/* in the controller class */ public function actionCreate() { $model=new YourModel; $this->performAjaxValidation($model); if(isset($_POST['YourModel'])) { $model->attributes=$_POST['YourModel']; if($model->save()) $this->redirect(array('view','id'=>$model->id)); } $this->render('create',array( 'model'=>$model, )); } /* in the create.php view */ .... echo $this->renderPartial('_form', array('model'=>$model)); ....