老师,按照教程操作,在controllers 的方法中指定公共模块:
比如我在 m 布局中的公共模块的名称为 m:
public function actionIndex()
{
$this->layout = "m"; //只要写这个就报错
return $this->render('index');
}
错误信息为:
View not Found – yii\base\ViewNotFoundException
The view file does not exist: E:\www\yii\modules\admin\views\layouts\m.php
1. in E:\www\yii\vendor\yiisoft\yii2\base\View.php at line 233
224225226227228229230231232233234235236237238239240241242 {
$viewFile = $requestedFile = Yii::getAlias($viewFile);
if ($this->theme !== null) {
$viewFile = $this->theme->applyTo($viewFile);
}
if (is_file($viewFile)) {
$viewFile = FileHelper::localize($viewFile);
} else {
throw new ViewNotFoundException("The view file does not exist: $viewFile");
}
$oldContext = $this->context;
if ($context !== null) {
$this->context = $context;
}
$output = '';
$this->_viewFiles[] = [
'resolved' => $viewFile,
2. in E:\www\yii\vendor\yiisoft\yii2\base\Controller.php at line 399 – yii\base\View::renderFile('E:\www\yii\modules\admin\views\l...', ['content' => ' <!DOCTYPE html> <html> <head...'], app\modules\admin\controllers\DefaultController)
3. in E:\www\yii\vendor\yiisoft\yii2\base\Controller.php at line 385 – yii\base\Controller::renderContent(' <!DOCTYPE html> <html> <head...')
4. in E:\www\yii\modules\admin\controllers\DefaultController.php at line 18 – yii\base\Controller::render('index')
121314151617181920 /**
* 品牌首页
*/
public function actionIndex()
{
$this->layout = "m";
return $this->render('index');
}
}
5. app\modules\admin\controllers\DefaultController::actionIndex()
6. in E:\www\yii\vendor\yiisoft\yii2\base\InlineAction.php at line 57 – call_user_func_array([app\modules\admin\controllers\DefaultController, 'actionIndex'], [])
7. in E:\www\yii\vendor\yiisoft\yii2\base\Controller.php at line 157 – yii\base\InlineAction::runWithParams([])
8. in E:\www\yii\vendor\yiisoft\yii2\base\Module.php at line 528 – yii\base\Controller::runAction('index', [])
9. in E:\www\yii\vendor\yiisoft\yii2\web\Application.php at line 103 – yii\base\Module::runAction('admin/default/index', [])
10. in E:\www\yii\vendor\yiisoft\yii2\base\Application.php at line 386 – yii\web\Application::handleRequest(yii\web\Request)
11. in E:\www\yii\web\index.php at line 19 – yii\base\Application::run()
13141516171819if(file_exists("/www/version/version")){
define("RELEASE_VERSION",trim( file_get_contents("/www/version/version") ) );
}else{
define( "RELEASE_VERSION",time() );
}
(new yii\web\Application($config))->run();
$_COOKIE = [
'SL_G_WPT_TO' => 'zh-CN',
'SL_GWPT_Show_Hide_tmp' => 'undefined',
'SL_wptGlobTipTmp' => 'undefined',
'_csrf' => 'b9933321a3562a206c2c3597033595aa6f9556e27f39195eef54eff84cf4e07ca:2:{i:0;s:5:"_csrf";i:1;s:32:"tllYU4T98BwvmFBXh1UMBPlChcd92PT8";}',
];
如果我不在 actionIndex 方法中指定m的公共模块,而是在其它页面中这样写:
<?php $this->beginContent("@app/modules/admin/layouts/m.php"); ?>
.....
<?php $this->endContent(); ?>
这样写不报错,也可以显示正常。但是每个页面都得写一遍 beginContent / endContent,很烦。
我也找不到是什么原因导致的,请老师指点一下,谢谢!
登录后可查看更多问答,登录/注册