Gii-generated form view doesn’t work (for me)

Hi, I’m new to this forum and Yii. Here’s my question as posted at but got no answers:

I’m using Yii, and used the Gii code generator to generate a form from a Model.

I’m loading the view this way:

public function actionIndex()


	$this->render( 'index', array(

		'form'=> $this->renderPartial( 'the_form', NULL, true )

		) );


The form view is structured this way:

<?php $form = $this->beginWidget('CActiveForm', array(



)); ?>

<div class="row">

	<?php echo $form->textField($model,'IdUser'); ?>

	<?php echo $form->error($model,'IdUser'); ?>



But I get an error from the textField() method:

get_class() expects parameter 1 to be object, null given

At: /yiiframework/web/helpers/CHtml.php(1894)

Stack trace:  

#0 /yiiframework/web/helpers/CHtml.php(1894): get_class()

#1 /yiiframework/web/helpers/CHtml.php(1870): resolveName()

#2 /yiiframework/web/helpers/CHtml.php(1164): resolveNameID()

#3 /yiiframework/web/widgets/CActiveForm.php(374): activeTextField()

#4 /protected/views/resume/resume_form.php(11): CActiveForm->textField()

Ok, the question would be: what’s wrong and how can I fix it?



You need to pass, as parameter 2 to render/renderPartial, an object of a class inherited from CModel (e.g CActiveRecord, CFormModel).


You need to declare parameter 2 as array(‘model’=>$whatever). This will define $model in the view.


Oh you’re right, I’m using $model in the view but it’s not being passed to it! what a dumb error.