Yii2 - 位于子文件夹中的渲染视图
Yii2 - Render view located in subfolder
我正在使用 Yii2,我想知道从控制器呈现位于 views 目录的子文件夹中的文件的正确方法是什么。比如我有以下情况:
views
-campus (carpeta)
--actividad (subcarpeta)
---2020.php (vista)
到目前为止,我已经尝试了这个选项但没有成功:
return $this->render('/actividad/2020',[]);
return $this->render('/actividad/2020',[],$this->context);
return $this->render('2020',[],$this->context);
return $this->render('@app/views/campus/actividad/2020',[]);
return $this->render('//actividad/2020',[]);
我的控制器CampusController
:
<?php
namespace frontend\controllers;
class CampusController extends \yii\web\Controller
{
public function action2020()
{
return $this->render('actividad/2020');
//return $this->render('/campus/actividad/2020');
//return $this->render('//campus/actividad/2020');
//return $this->render('@app/views/campus/actividad/2020');
}
}
如果您在 CampusController
,想要呈现 2020.php
,并拥有您在问题中显示的文件夹结构:
views
-campus (carpeta)
--actividad (subcarpeta)
---2020.php (vista)
以下所有方法都有效:
return $this->render('actividad/2020');
return $this->render('/campus/actividad/2020');
return $this->render('//campus/actividad/2020');
return $this->render('@app/views/campus/actividad/2020');
如果您不向视图传递任何参数,您可以传递一个空数组,但也可以删除第二个参数。
您 需要 return $this->render(...)
的结果,在您的问题中,您似乎在调用 return 在之后,那将是return一个空响应,而不是呈现视图文件的结果。
我正在使用 Yii2,我想知道从控制器呈现位于 views 目录的子文件夹中的文件的正确方法是什么。比如我有以下情况:
views
-campus (carpeta)
--actividad (subcarpeta)
---2020.php (vista)
到目前为止,我已经尝试了这个选项但没有成功:
return $this->render('/actividad/2020',[]);
return $this->render('/actividad/2020',[],$this->context);
return $this->render('2020',[],$this->context);
return $this->render('@app/views/campus/actividad/2020',[]);
return $this->render('//actividad/2020',[]);
我的控制器CampusController
:
<?php
namespace frontend\controllers;
class CampusController extends \yii\web\Controller
{
public function action2020()
{
return $this->render('actividad/2020');
//return $this->render('/campus/actividad/2020');
//return $this->render('//campus/actividad/2020');
//return $this->render('@app/views/campus/actividad/2020');
}
}
如果您在 CampusController
,想要呈现 2020.php
,并拥有您在问题中显示的文件夹结构:
views
-campus (carpeta)
--actividad (subcarpeta)
---2020.php (vista)
以下所有方法都有效:
return $this->render('actividad/2020');
return $this->render('/campus/actividad/2020');
return $this->render('//campus/actividad/2020');
return $this->render('@app/views/campus/actividad/2020');
如果您不向视图传递任何参数,您可以传递一个空数组,但也可以删除第二个参数。
您 需要 return $this->render(...)
的结果,在您的问题中,您似乎在调用 return 在之后,那将是return一个空响应,而不是呈现视图文件的结果。