Yii Framework Forum: View Communicates With Model. Wrong? - Yii Framework Forum

Jump to content

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

View Communicates With Model. Wrong?

#1 User is offline   CoderK 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 13-June 13

Posted 02 July 2013 - 02:52 AM

I just finished reading this book and I saw that in various places, the Model's methods are being called directly from the View.

For instance in file: trackstar/protected/views/issue/_form.php

there is this code:


<div class="row">
	<?php echo $form->labelEx($model,'type_id'); ?>
	<?php echo $form->dropDownList($model,'type_id', $model->getTypeOptions()); ?>
	<?php echo $form->error($model,'type_id'); ?>
</div>



Wouldn't that break the MVC practices/rules that the View should not be aware of the Model and instead the controller has to give these values directly to the View?
Or is this totally accepted in Yii?
0

#2 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 880
  • Joined: 20-April 11
  • Location:India

Posted 02 July 2013 - 04:33 AM

Model-name::model()->getTypeOptions());


this is the standard use. but if we know that the model itself we can call like that.
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
1

#3 User is offline   RolandoEfren 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 07-January 13

Posted 26 October 2013 - 03:45 PM

My opinion is that you can use the bussiness model's properties anywhere, as long as its generation and integrity are hidden and guaranteed within the model's code. In fact, passing (bussiness) model objects to the view layer is the cleanest, simplest, and most direct way of providing information without artificially multiplying ad-hoc data carriers all over the application, or overloading the controllers with too much knowledge of the view's detailed needs. MVC at its best.
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