简体   繁体   English

CakePHP插件抛出“ Missing View”错误,但视图文件退出

[英]CakePHP plugin throws “Missing View” error but view file exits

I'm writing a basic plugin for my cakePHP 2.x app following the instructions in the book . 我正在按照书中的说明为我的cakePHP 2.x应用程序编写一个基本的插件。

I've created the directory/file structure with a MyPluginAppController.php and MyPluginAppModel.php. 我已经使用MyPluginAppController.php和MyPluginAppModel.php创建了目录/文件结构。

I added CakePlugin::load('MyPlugin'); 我添加了CakePlugin::load('MyPlugin'); to the parent app's bootstrap.php file. 到父应用程序的bootstrap.php文件。

Then I created one Controller and Model. 然后,我创建了一个控制器和模型。 But for some reason when I try to view mysite.dev/(admin)/my_plugin/my_model/ I get a "Missing View" error. 但是由于某些原因,当我尝试查看mysite.dev/(admin)/my_plugin/my_model/出现“ Missing View”错误。 It says to confirm that the view file exists, which it does! 它说要确认视图文件存在,确实如此!

I don't think I skipped any steps from the book. 我认为我没有跳过本书中的任何步骤。 What am I doing wrong? 我究竟做错了什么?

Update: 更新:

Controller path: app/Plugin/MyPlugin/Controller/MyModelController.php 控制器路径: app/Plugin/MyPlugin/Controller/MyModelController.php

View path: app/Plugin/MyPlugin/View/MyModel/admin_index.php 查看路径: app/Plugin/MyPlugin/View/MyModel/admin_index.php

URL: http://mysite.dev/admin/my_plugin/my_model/ 网址: http://mysite.dev/admin/my_plugin/my_model/http://mysite.dev/admin/my_plugin/my_model/

Rename this file 重命名这个文件

app/Plugin/MyPlugin/View/MyModel/admin_index.php

To this extension .ctp 此扩展名.ctp

app/Plugin/MyPlugin/View/MyModel/admin_index.ctp

This is a common mistake. 这是一个常见的错误。

I was't using a plugin so my case was a bit different. 我没有使用插件,所以情况有所不同。 However, this question shows up on the search results page, so I'll post this here. 但是,此问题显示在搜索结果页面上,因此我将在此处发布。

This is the problematic controller. 这是有问题的控制器。

<?php 

class ArticlesController extends AppController {

    public function beforeFilter() {
    }

    public function view() {
        // do stuff
    }

}

The problem: 问题:

CakePHP kept showing me the following error: CakePHP不断向我显示以下错误:

Missing View 缺少视野

Error: The view for ArticlesController::view() was not found. 错误:找不到ArticlesController :: view()的视图。

Confirm you have created the file: Articles/view.ctp in one of the following paths: 确认您已创建文件:Articles / view.ctp,位于以下路径之一:

Debugging: 调试:

I checked all paths it suggested using is_readable() and the stat command to make sure the view file exists and is indeed readable by PHP. 我使用is_readable()stat命令检查了建议的所有路径,以确保视图文件存在并且确实可以被PHP读取。

Solution: 解:

The issue there is the empty beforeFilter() . 那里的问题是空的beforeFilter() As soon as I removed it everything worked. 我将其删除后,一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM