简体   繁体   中英

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 .

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/

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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