[英]How to custom render function of Yii2 framework
我想將yii2的views文件夾更改為以下結構
views
----default
----site
----index.php
----error.php
----login.php
在siteController中,我正在使用以下代碼
public function actionIndex(){
return $this->render('default/index');
}
和錯誤
The view file does not exist: D:\wamp\www\yii2\backend\views\site\default/index.php
請幫我
使用當前代碼, 站點控制器將在其視圖文件夾/views/site
下搜索視圖文件,您需要獲取正確的路徑:
$this->render('../default/site/index');
我建議創建一個別名以使其更加靈活,例如在主本地文件中使用@default_views :
'aliases' => [
'@default_views' => '../default/',
因此,該功能:
public function actionIndex(){
return $this->render(Yii::getAlias('@default_views') . 'site/index');
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.