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

后端 未结 2 1751
暖寄归人
暖寄归人 2020-12-22 07:53

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

相关标签:
2条回答
  • 2020-12-22 08:43

    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.

    0 讨论(0)
  • 2020-12-22 08:48

    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.

    0 讨论(0)
提交回复
热议问题