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

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

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'); ?>

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?

#2 User is offline   Rajith R 

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

Posted 02 July 2013 - 04:33 AM


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

#3 User is offline   RolandoEfren 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • 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.

Share this topic:

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

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