Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

render a view from another controller, yii

Tags:

yii

yii1.x

The controller:

controllers |-FooController.php |-BarController.php 

The views:

view |-foo| |    |-index.php |    |-error.php | |-bar|      |-index.php 

How to render the error.php view with an action of the bar controller? I have tried:

$this->render('foo/error'); 

But it doesn't work.

like image 551
Cedric Avatar asked Feb 11 '14 10:02

Cedric


Video Answer


2 Answers

try this

$this->render('//foo/error'); 
like image 184
Let me see Avatar answered Sep 19 '22 13:09

Let me see


If you don't echo it, you will get a blank page. The correct way is

<?=    $this->render('//foo/error'); ?> 

or

<?php      echo $this->render('//foo/error'); ?>  

This also works for Yii2

like image 26
ovicko Avatar answered Sep 19 '22 13:09

ovicko