render a view from another controller, yii

别来无恙 提交于 2021-02-05 20:59:13

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!