Track Star Application Update Issue

Hi All,

I’m new to yii and was using yii 1.1.4 and following the yii book,to build a TrackStar Application,

the problem i’m facing was the OWNER and REQUESTER Drop-Down was not populating while updating the Issue. It is working fine for Creating an Issue but when I try to Update an Issue It says

Fatal error: Call to a member function getProject() on a non-object in /var/www/trackstar/protected/views/issue/_form.php on line 45.

[b]

[/b]

Can anyone help me to solve this problem…

Thanks in Advance.

[b]

[/b]

[b]

[/b]

Are you passing the project ID to the update page (in the URL)?

Same problem here (almost). Creating an issue works fine, but when updating I got this error meesage


Owner Fatal error: Call to a member function getUserOptions() on a non-object in /trackstar/protected/views/issue/_form.php on line 43 

which leads to ugly presentation because the layout was gone (actually the same happens with the requester row).

Here are the problematic codes:




        <div class="row">

		<?php echo $form->labelEx($model,'owner_id'); ?>

		<?php echo $form->dropDownList($model,'owner_id', $this->getProject()->getUserOptions()); ?>

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

	</div>


	<div class="row">

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

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

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

	</div>



If I uncomment the dropDownList rows, the problem will disappear along with the combo box of course, which I’m sure I will need someday.

Please enlighten me what part of the tutorial I have I missed.

I’m using Yii 1.1.4 as well.

How can that be the same problem when one error is getProject() and yours is getUserOptions() ? ???

(almost) is not near enough, should start your own thread :)

Yes, this is 1 part of the issue you are having. Some of the functionality in the Trackstar application is intentionally left up to the reader to implement, and updating issues is one such example. In order to properly implement issue updating you’ll need to

  1. Alter the "Update Issue" link such that the project id is also passed (the code added in the IssueController::filterProjectContext() method is expecting this as a querystring param by the name of "pid"). So, the url will need to be of the format (assuming issue # 1 on project #1): index.php?r=issue/update&id=1&pid=1

  2. Alter IssueControler::filters method and add the ‘update’ as one of the actions filtered by the ‘projectContext’ filter, i.e.:


/**

     * @return array action filters

     */

	public function filters()

	{

		return array(

			'accessControl', // perform access control for CRUD operations

			'projectContext + create index admin update', //add update method to the list of filtered actions

		);

	}



Hope this helps. Post again if you continue to have issues with this implementation.

I believe you ARE having the same issue. Please see my post above outlining some hints on how to move forward with implementing Issue update functionality int he Trackstar application.

I think the MAIN problem is "Owner Requester not Working in Update", not the getProject() or getUserOptions(), thus the assumption "(almost)".

@Jefftulsa: Thanks for the helpful reply. I’ll try that as soon as I get home, and inform you of the result.

Yes, It worked.Thanks.

Thanks, Its working fine now.

Affirmative. After adding the word “update” in the filter, and adding “‘pid’=>$model->project->id” in the view.php, everything works fine now.

Cheers! :))

Glad it worked, and sorry if this was the source of frustration.

However, just to be clear, this is NOT an error in the code in the book or in the downloaded src code. This was intentionally not implemented and left to the readers as an exercise (as are some of the other features of the Trackstar application).

I was more of challenged than frustrated actually :D

If I may suggest and if there will be another book for Yii, I wish to include a part in every chapter (probably after summary) wherein the users can test their so-far-learned-things (therefore clearly stating that there are exercises, so as to avoid the tendency of some readers, like me, to think that there are missing parts), and the answers at the back of the book if applicable (man I miss high school :P)

I have already finished reading the book, and I really enjoyed reading it.

More power to you guys!

Hey, I apparently posted a different solution to this problem (didn’t see this thread, SORRY!).

http://www.yiiframework.com/forum/index.php?/topic/12999-ch-6-note-about-exit-exercise-viewissueupdatephp/

Anyway, to sum it up: WHY would you pass the pid to the update page? every issue already has a project_id…

instead I added the following to actionUpdate after loadModule():


$this->loadProject($model->project->id);

Please correct me if my assumptions or methods are wrong, I’m still new to Yii.

Hello Bob,

Nothing wrong with your assumptions at all, and you are absolutely correct. Once you have a valid Issue model in hand, just use the wonderful features of Yii’s relational AR model to retrieve the related project id, as you have indicated. The other solution thrown out there was a quick and dirty one, simply following in the exact footsteps of the create approach using the filter (and a passed in identifier) to provide the context. Your solution is absolutely fine. (glad you are learning and sharing :)).

We also can do this :

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

instead of :

$this->loadProject($model->project->id);

Good luck :)