Yii Framework Forum: [Chapter 5] Generating The Data To Populate The Dropdowns - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

[Chapter 5] Generating The Data To Populate The Dropdowns

#1 User is offline   thevenin 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 17-January 13

Posted 02 April 2013 - 04:57 AM

Hi guys,

to change
owner_id

and
requester_id

text fields to dropdowns in a new issue form I changed
/views/issue/_form.php
file according to instructions in chapter 5:

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


to
<?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?

Thanks.
0

#2 User is offline   Abhishek Shah 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 89
  • Joined: 20-July 12
  • Location:New Jersey,USA

Posted 02 April 2013 - 05:13 AM

why you use .$model->project->getUserOptions(),according to me it shoule be $model->getUserOptions().
Feel free to ask for help,
Abhishek.
Freelancer.
Yii Basic Gii With Export Pdf Excel
0

#3 User is offline   thevenin 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 17-January 13

Posted 02 April 2013 - 06:29 AM

View Postabhishek shah rudrasoftech, on 02 April 2013 - 05:13 AM, said:

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).

Therefore
$model

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

getUserOptions()

method of that model.
0

#4 User is offline   Berni Chenlo 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 13-May 13

Posted 13 May 2013 - 06:39 PM

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.
0

#5 User is offline   Ravi Bhalodiya 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 64
  • Joined: 27-August 12
  • Location:Gujarat India

Posted 06 July 2013 - 06:01 AM

View PostBerni Chenlo, on 13 May 2013 - 06:39 PM, said:

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.
Regards
Ravi Bhalodiya.
0

#6 User is offline   Sami Ghnaim 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 08-July 13

Posted 08 July 2013 - 05:02 PM

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;

Regards,
Sami Ghnaim.
0

#7 User is offline   MartindeGroot 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 07-July 13

Posted 09 July 2013 - 09:29 AM

View PostSami Ghnaim, on 08 July 2013 - 05:02 PM, said:

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;

Regards,
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.

Regards,

Martin de Groot
0

#8 User is offline   fvthree 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 22-November 13

Posted 23 November 2013 - 03:16 PM

Still has problems with this
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users