Yii Framework Forum: Model And View problem.. - Yii Framework Forum

Jump to content

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

Model And View problem.. Rate Topic: ***** 1 Votes

#1 User is offline   reflow 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 07-January 11

Posted 15 January 2011 - 11:26 AM

If I am in the view, and I want to retrieve information from a model which differs from the regular model that uses that the view. How do i do that?
0

#2 User is offline   Yoda Pop 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 54
  • Joined: 11-August 10
  • Location:Ontario, Ca

Posted 15 January 2011 - 03:16 PM

The Model-View-Controller architecture is designed to keep the classes in each organizational sphere independent of each other (low coupling). So there is no "regular model" that uses the view. You can pass any model you want into the view. You can handle the implementing and passing of a model in the Controller's action methods. For example,

  public function actionIndex() {
	//get the Active Record
	$model = ARClass::model()->find('id=1');
	//pass the model to the index view
	$this->render('index',array('model'=>$model));
	//now you can access the model in the view as $model
  }


If you want to learn more read the Yii documentation. It is excellent!
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