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

…衆ロ難τιáo~ 提交于 2019-12-18 09:48:20

问题


I'm writing a basic plugin for my cakePHP 2.x app following the instructions in the book.

I've created the directory/file structure with a MyPluginAppController.php and MyPluginAppModel.php.

I added CakePlugin::load('MyPlugin'); to the parent app's bootstrap.php file.

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. 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

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

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


回答1:


Rename this file

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

To this extension .ctp

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

This is a common mistake.




回答2:


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:

Missing View

Error: The view for ArticlesController::view() was not found.

Confirm you have created the file: Articles/view.ctp in one of the following paths:

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.

Solution:

The issue there is the empty beforeFilter(). As soon as I removed it everything worked.



来源:https://stackoverflow.com/questions/16921021/cakephp-plugin-throws-missing-view-error-but-view-file-exits

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!