YII 2.0.3视图不呈现。它只是空白。调用索引时仅显示1

时间:2015-03-15 12:05:12

标签: php yii yii2

我正在浏览制作自定义应用程序 与 Web应用程序开发的Yii 2 章节 与Yii 2和PHP 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; 
      }
      .......
      .......
 }

请注意我的模特文件夹。它是客户,而views / controller文件夹/命名空间是客户 s s 。表格客户。 我的模型在 project-folder \ frontend \ models \ customer 中 我在 project-folder \ frontend \ views \ customers 中有index.php布局。 控制器位于 project-folder \ frontend \ controllers 中。我在视图文件中几乎没有任何内容..

<?php
   $this->title = 'Index for customers';
?>
<div class="site-index">
Echo Out Loud
</div>

在空白页面显示1! Here is what the view shows..

如果我将代码更改为此..

<?php
   $this->title = 'Index for customers';
?>
<div class="site-index">
Echo Out Loud
</div>
<?php
die();

它呈现视图,但不包括页眉和页脚的布局等。没有头标记,没有脚本,样式......没有。 enter image description here

但是,站点控制器索引和其他预构建的视图正常呈现!没问题。在拉我的头发的时候,我错过了什么?

1 个答案:

答案 0 :(得分:11)

您的操作将显示操作返回的内容。在您的情况下,您的操作返回“true”,因此显示为1(对于true)。如果你想让它显示视图,那么你需要返回它,所以

 class CustomersController extends Controller{ 
  public function actionIndex() {   
     $records = $this->findRecordsByQuery();
     return $this->render('index', compact('records'));
     }
  .......
  .......
 }
相关问题