我正在阅读使用Yii 2和Web应用程序开发的Yii 2章节制作自定义应用程序,由Mark Safronov和Jeffrey Winesett完成.但是,我卡住了很糟糕!当我尝试(在localhost wamp服务器上运行高级模板)时,视图不呈现... http://localhost/furni/frontend/web/index.php?r = customers 它正在触发的操作是..
class CustomersController extends Controller{
public function actionIndex() {
$records = $this->findRecordsByQuery();
$this->render('index', compact('records'));
return true;
}
.......
.......
}
Run Code Online (Sandbox Code Playgroud)
请注意我的模型文件夹.它是客户,而视图/控制器文件夹/命名空间是客户的,带有s.表是客户.我在project-folder\frontend\models\customer中有我的模型
我在project-folder\frontend\views\customers中有index.php布局.Controller位于project-folder\frontend\controllers中.我在视图文件中几乎没有任何内容..
<?php
$this->title = 'Index for customers';
?>
<div class="site-index">
Echo Out Loud
</div>
Run Code Online (Sandbox Code Playgroud)
它在空白页面中显示1! 
如果我将代码更改为此..
<?php
$this->title = 'Index for customers';
?>
<div class="site-index">
Echo Out Loud
</div>
<?php
die();
Run Code Online (Sandbox Code Playgroud)
它呈现视图,但不包括页眉和页脚的布局等.没有头标记,没有脚本,样式..没有.

但是,站点控制器索引和其他预先构建的视图正常呈现!没问题.在拉我的头发的时候,我错过了什么?
Joe*_*ler 11
您的操作将显示操作返回的任何内容.在您的情况下,您的操作返回"true",因此显示为1(对于true).如果您希望它显示视图,那么您需要返回它,所以
class CustomersController extends Controller{
public function actionIndex() {
$records = $this->findRecordsByQuery();
return $this->render('index', compact('records'));
}
.......
.......
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5269 次 |
| 最近记录: |