Yii Framework Forum: Include views - Yii Framework Forum

Jump to content

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

Include views yii2 views

#1 User is offline   Cabral 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 28-April 14

  Posted 05 December 2017 - 08:30 PM

Hi!

I want to display different view for different controller in one view!
What is the best practices for this?

Now i have called de views from another controller like this:



echo \Yii::$app->view->render('@app/views/anothercontroller/view',[
                        'datamodel' => $model2,
                                         ]);



This is the beste method to include views in one view?

Thanks for help
0

#2 User is offline   alrazi 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,488
  • Joined: 08-August 12
  • Location:Durban, South Africa

Posted 06 December 2017 - 12:29 AM

you are on the right track render is how usually you render a view or a partial view.

if you are calling it in a view or controller, you don't need to reference the full component you can call render on current context like so
echo $this->render('@app/views/anothercontroller/view', [
    'datamodel' => $model2,
]);

1

#3 User is offline   Cabral 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 28-April 14

Posted 06 December 2017 - 04:43 AM

Thanks


View Postalrazi, on 06 December 2017 - 12:29 AM, said:

you are on the right track render is how usually you render a view or a partial view.

if you are calling it in a view or controller, you don't need to reference the full component you can call render on current context like so
echo $this->render('@app/views/anothercontroller/view', [
    'datamodel' => $model2,
]);


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