[Chapter 5] Generating The Data To Populate The Dropdowns

Hi guys,

to change




text fields to dropdowns in a new issue form I changed


file according to instructions in chapter 5:


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


<?php echo $form->dropDownList($model,'requester_id', $model->project->getUserOptions()); ?>

Now, when a create issue page is opened, the following error occurs:

Object of class Project could not be converted to string

/models/Project.php, getUserOptions():


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


public function getUserOptions()


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

	return $usersArray;


Does anyone have similar problems?


why you use .$model->project->getUserOptions(),according to me it shoule be $model->getUserOptions().

I used it because the code above is executed in context of Issue model (by Issue controller).



variable refers to Issue model. Only after that we can access Project model and


method of that model.

Did you finally solve it?

I have the same problem in views/issue/_form.php line 41

<?php echo $form->dropDownList($model,‘owner_id’, $model->project->getUserOptions()); ?>

Returns Recoverable error:

Object of class Project could not be converted to string

Thank you.

This problem occurs due to your getUserOptions method. This returns object… So you have to pass this in CHtml::listData method. So it convert into an array that dropDown arguments.

On the controllers/IssueController.php

in the function actionCreate.

check if the $model->project_id = $this->_project->id; not as $model->project_id = $this->_project;


Sami Ghnaim.

I had no problems with this, but as soon as I changed the code in the second line from IssueController / actionCreate method to:

$model->project_id = $this->_project;

I immediately got the error mentioned at the start of this post.

After having had problems with copying code from the Kindle reader of the book (Kindle for PC) to my editor, I started using the code of the book which can be downloaded as the book tells you.

I can nicely put the relevant downloaded file and my own file side by side in the editor and copy the required sections over to my own file.


Martin de Groot

Still has problems with this