Can't Get Owner And Requester Username Dropdown

I am on chapter six in the book and I got some difficulties in showing drop down list of username.

I put get_project function in issue controller:

    public function getProject()


{


     return $this->_project;


}

I put getUserOptions in project model:

   public function getUserOptions()


{


         $usersArray = CHtml::listData($models, 'id', 'username');


	 return $usersArray;


}

I set relations as:

    In project model:


    public function relations()


{


	// NOTE: you may need to adjust the relation name and the related


	// class name for the relations automatically generated below.


	return array(


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


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


	);


}





    In Issue model:





    public function relations()


{


	// NOTE: you may need to adjust the relation name and the related


	// class name for the relations automatically generated below.


	return array(


		'requester' => array(self::BELONGS_TO, 'User', 'requester_id'),


		'owner' => array(self::BELONGS_TO, 'User', 'owner_id'),


		'project' => array(self::BELONGS_TO, 'Project', 'project_id'),


	);


}

And I get a blank page for owner drop down list. (see picture for clearer problem.)

public function getUserOptions()

{

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

return $usersArray;

}

sorry forget to update the bold part.

And… here is the view of create new issue:

<?php $this->widget(‘zii.widgets.CDetailView’, array(

'data'=&gt;&#036;model,


'attributes'=&gt;array(


	'id',


	'name',


	'description',


	array(


		'name'=&gt;'type_id',


	    'value'=&gt;CHtml::encode(&#036;model-&gt;getTypeText()),


	),


	array(


	    'name'=&gt;'status_id',


	    'value'=&gt;CHtml::encode(&#036;model-&gt;getStatusText()),


	),


	array(


	    'name'=&gt;'owner_id',


	    'value'=&gt;CHtml::encode(&#036;model-&gt;owner-&gt;username),


	),


	array(


	    'name'=&gt;'requester_id',


	    'value'=&gt;CHtml::encode(&#036;model-&gt;requester-&gt;username),


	)


),

));

?>

Hi, did you resolve the problem?if not try to change your getUserOptions into

public function getUserOptions(){

$usersArray = CHtml::listData($this->tblUsers, ‘id’, ‘username’);//instead of users

return $usersArray;

}

Hope this helps

I got the same issue no drop down on Owner_Id and requester_id.

Project.php

<?php

/**

  • This is the model class for table "tbl_project".

  • The followings are the available columns in table ‘tbl_project’:

  • @property integer $id

  • @property string $name

  • @property string $description

  • @property string $create_time

  • @property integer $create_user_id

  • @property string $update_time

  • @property integer $update_user_id

*/

class Project extends CActiveRecord

{

/**


 * Returns the static model of the specified AR class.


 * @param string &#036;className active record class name.


 * @return Project the static model class


 */


public static function model(&#036;className=__CLASS__)


{


	return parent::model(&#036;className);


}





/**


 * @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('create_user_id, update_user_id', 'numerical', 'integerOnly'=&gt;true),


		array('name', 'length', 'max'=&gt;128),


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


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


		// 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'=&gt;'search'),


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


	);


}





/**


 * @return array relational rules.


 */


public function relations()


{


	// NOTE: you may need to adjust the relation name and the related


	// class name for the relations automatically generated below.


	return array(


		'issues' =&gt; array(self::HAS_MANY, 'Issue', 'project_id'),


           'users' =&gt; array(self::MANY_MANY, 'User', 'tbl_project_user_assignment(project_id, user_id)'),


	);


}





/**


 * @return array customized attribute labels (name=&gt;label)


 */


public function attributeLabels()


{


	return array(


		'id' =&gt; 'ID',


		'name' =&gt; 'Name',


		'description' =&gt; 'Description',


		'create_time' =&gt; 'Create Time',


		'create_user_id' =&gt; 'Create User',


		'update_time' =&gt; 'Update Time',


		'update_user_id' =&gt; 'Update User',


	);


}





/**


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


 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.


 */


public function search()


{


	// Warning: Please modify the following code to remove attributes that


	// should not be searched.





	&#036;criteria=new CDbCriteria;





	&#036;criteria-&gt;compare('id',&#036;this-&gt;id);


	&#036;criteria-&gt;compare('name',&#036;this-&gt;name,true);


	&#036;criteria-&gt;compare('description',&#036;this-&gt;description,true);


	&#036;criteria-&gt;compare('create_time',&#036;this-&gt;create_time,true);


	&#036;criteria-&gt;compare('create_user_id',&#036;this-&gt;create_user_id);


	&#036;criteria-&gt;compare('update_time',&#036;this-&gt;update_time,true);


	&#036;criteria-&gt;compare('update_user_id',&#036;this-&gt;update_user_id);





	return new CActiveDataProvider(&#036;this, array(


		'criteria'=&gt;&#036;criteria,


	));


}


/**


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


*/


public function getUserOptions()


{


 &#036;usersArray = CHtml::listData(&#036;this-&gt;users, 'id', 'username');


  return &#036;usersArray;


}

}

My Issue/view.php

<?php

/* @var $this IssueController */

/* @var $model Issue */

$this->breadcrumbs=array(

'Issues'=&gt;array('index'),


&#036;model-&gt;name,

);

$this->menu=array(

array('label'=&gt;'List Issue', 'url'=&gt;array('index')),


array('label'=&gt;'Create Issue', 'url'=&gt;array('create')),


array('label'=&gt;'Update Issue', 'url'=&gt;array('update', 'id'=&gt;&#036;model-&gt;id)),


array('label'=&gt;'Delete Issue', 'url'=&gt;'#', 'linkOptions'=&gt;array('submit'=&gt;array('delete','id'=&gt;&#036;model-&gt;id),'confirm'=&gt;'Are you sure you want to delete this item?')),


array('label'=&gt;'Manage Issue', 'url'=&gt;array('admin')),

);

?>

<h1>View Issue #<?php echo $model->id; ?></h1>

<?php $this->widget(‘zii.widgets.CDetailView’, array(

'data'=&gt;&#036;model,


'attributes'=&gt;array(


	'id',


	'name',


	'description',


	'type_id',


	'status_id'


	array(


	'name'=&gt;'owner_id',


	'value'=&gt;CHtml::encode(&#036;model-&gt;owner-&gt;username),


	),


	array(


	'name'=&gt;'requester_id',


	'value'=&gt;CHtml::encode(&#036;model-&gt;requester-&gt;username),


	)


),

)); ?>

My Issue/_form.php

<?php

/* @var $this IssueController */

/* @var $model Issue */

/* @var $form CActiveForm */

?>

<div class="form">

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

'id'=&gt;'issue-form',


'enableAjaxValidation'=&gt;false,

)); ?>

&lt;p class=&quot;note&quot;&gt;Fields with &lt;span class=&quot;required&quot;&gt;*&lt;/span&gt; are required.&lt;/p&gt;





&lt;?php echo &#036;form-&gt;errorSummary(&#036;model); ?&gt;





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


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


	&lt;?php echo &#036;form-&gt;textField(&#036;model,'name',array('size'=&gt;60,'maxlength'=&gt;256)); ?&gt;


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


&lt;/div&gt;





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


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


	&lt;?php echo &#036;form-&gt;textField(&#036;model,'description',array('size'=&gt;60,'maxlength'=&gt;2000)); ?&gt;


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


&lt;/div&gt;





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


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


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


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


&lt;/div&gt;





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


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


	&lt;?php echo &#036;form-&gt;dropDownList(&#036;model,'type_id', &#036;model-&gt;getTypeOptions()); ?&gt;


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


&lt;/div&gt;





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


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


	&lt;?php echo &#036;form-&gt;dropDownList(&#036;model,'status_id', &#036;model-&gt;getStatusOptions()); ?&gt;


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


&lt;/div&gt;





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


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


	&lt;?php echo &#036;form-&gt;dropDownList(&#036;model,'owner_id', &#036;this-&gt;getProject()-&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;this-&gt;getProject()-&gt;getUserOptions()); ?&gt;


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


&lt;/div&gt;





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


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


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


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


&lt;/div&gt;





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


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


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


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


&lt;/div&gt;





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


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


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


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


&lt;/div&gt;





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


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


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


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


&lt;/div&gt;





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


	&lt;?php echo CHtml::submitButton(&#036;model-&gt;isNewRecord ? 'Create' : 'Save'); ?&gt;


&lt;/div&gt;

<?php $this->endWidget(); ?>

</div><!-- form -->

Thank you.