Yii Framework Forum: Ch.6 — Getproject And Getuseroptions - Yii Framework Forum

Jump to content

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

Ch.6 — Getproject And Getuseroptions Why those methods are stored where they are

#1 User is offline   Unruly Zen 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 20-September 12

Posted 20 September 2012 - 12:58 PM

In Chapter 6 (Iteration 3: Fixing the owner and requester fields), the author has us create two methods which will allow us to pull the list of users assigned to the Issue's project. The finished line in the form looks like this:
<?php echo $form->dropDownList($model, 'requester_id', $this->getProject()->getUserOptions()); ?>
.

I understand how and why each of the two methods work. What I don't understand is why the getProject method is in the Issue Controller but the getUserOptions method is in the Project Model. My best guess is that — generally — these methods would always be in the model, but since we had already created the _project array for the actionCreate() method in the Issue Controller, it was simpler to reference it there (rather than create a second one).

Any insight here would be fabulous!

Thanks in advance.
0

#2 User is offline   CeBe 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 482
  • Joined: 16-July 10
  • Location:Berlin. Germany

Posted 21 September 2012 - 05:38 PM

getProject was created to get the Project model when you are the controller. getUserOptions was implemented in the model because model is about data and known which user options are there, controller does not know that.

Why should a project model have a method getProject?
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