问题
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.
回答1:
try this
$this->render('//foo/error');
回答2:
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
来源:https://stackoverflow.com/questions/21699309/render-a-view-from-another-controller-yii