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.phpon line45.
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
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
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.
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).
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 )
I have already finished reading the book, and I really enjoyed reading it.
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 .