Chap5, getUserOption function

GetUserOption function is defined in Project Data Model class:

class Project extends CActiveRecord

{

/**


 * @return string the associated database table name


 */


public function tableName()


{


	return 'tbl_project';


}





/**


 * @return array validation rules for model attributes.


 */


public function rules()


{


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


	// will receive user inputs.


	return array(


		array('name, description', 'required'),


		array('create_user_id, update_user_id', 'numerical', 'integerOnly'=>true),


		array('name', 'length', 'max'=>255),


		array('create_time, update_time', 'safe'),


		// The following rule is used by search().


		// @todo Please remove those attributes that should not be searched.


		array('id, name, description, create_time, create_user_id, update_time, update_user_id', 'safe', 'on'=>'search'),


	);


}





/**


 * @return array relational rules.


 */


public function relations()


{


    return array(


        'issues' => array(self::HAS_MANY, 'Issue', 'project_id'),


        'users' => array(self::MANY_MANY, 'User', 'tbl_project_user_assignment(project_id, user_id)'),


    );


}





/**


 * @return array customized attribute labels (name=>label)


 */


public function attributeLabels()


{


	return array(


		'id' => 'ID',


		'name' => 'Name',


		'description' => 'Description',


		'create_time' => 'Create Time',


		'create_user_id' => 'Create User',


		'update_time' => 'Update Time',


		'update_user_id' => 'Update User',


	);


}





/**


 * Retrieves a list of models based on the current search/filter conditions.


 *


 * Typical usecase:


 * - Initialize the model fields with values from filter form.


 * - Execute this method to get CActiveDataProvider instance which will filter


 * models according to data in model fields.


 * - Pass data provider to CGridView, CListView or any similar widget.


 *


 * @return CActiveDataProvider the data provider that can return the models


 * based on the search/filter conditions.


 */


public function search()


{


	// @todo Please modify the following code to remove attributes that should not be searched.





	$criteria=new CDbCriteria;





	$criteria->compare('id',$this->id);


	$criteria->compare('name',$this->name,true);


	$criteria->compare('description',$this->description,true);


	$criteria->compare('create_time',$this->create_time,true);


	$criteria->compare('create_user_id',$this->create_user_id);


	$criteria->compare('update_time',$this->update_time,true);


	$criteria->compare('update_user_id',$this->update_user_id);





	return new CActiveDataProvider($this, array(


		'criteria'=>$criteria,


	));


}





/**


 * Returns the static model of the specified AR class.


 * Please note that you should have this exact method in all your CActiveRecord descendants!


 * @param string $className active record class name.


 * @return Project the static model class


 */


public static function model($className=__CLASS__)


{


	return parent::model($className);


}





/**


* @return array of valid users for this project, indexed by user IDs


*/


public function getUserOptions()


{


    $usersArray = CHtml::listData($this->users, 'id', 'username');


    return $usersArray;


}

}

and it is used in issue creation form as:

<div class="row">

	&lt;?php echo &#036;form-&gt;labelEx(&#036;model,'owner_id'); ?&gt;


	&lt;?php echo &#036;form-&gt;dropDownList(&#036;model,'owner_id', &#036;model-&gt;project-&gt;getUserOptions()); ?&gt;


	&lt;?php echo &#036;form-&gt;error(&#036;model,'owner_id'); ?&gt;


&lt;/div&gt;





&lt;div class=&quot;row&quot;&gt;


	&lt;?php echo &#036;form-&gt;labelEx(&#036;model,'requester_id'); ?&gt;


	&lt;?php echo &#036;form-&gt;dropDownList(&#036;model,'requester_id', &#036;model-&gt;project-&gt;getUserOptions()); ?&gt;


	&lt;?php echo &#036;form-&gt;error(&#036;model,'requester_id'); ?&gt;


&lt;/div&gt;

Its giving error:

Fatal error: Call to a member function getUserOptions() on null in C:\xampp\htdocs\trackstar\protected\views\issue\_form.php on line 48

How can we acess project user names from issue controller or issue model classes, I don’t have any idea.