简体   繁体   中英

CakePHP Themed application and plugin view elements missing

I use CakePHP 2.4.1 and after installing CakeDC comments plugin, I got the following Notice:

Notice (1024): Element Not Found: Elements\\comments\\flat\\main.ctp [CORE\\Cake\\View\\View.php, line 415]

My base application is using theme. I initialize theming from the AppController beforeFilter callback as follows:

class AppController extends Controller { 
     function beforeFilter(){
     App::uses('Security', 'Utility');
     $this->theme = 'Slate';  
     $this->layout = 'blog' ;
     } 
}

To solve this issue I tried two methods, one of them succeeded but the other is not as follows:

  1. Creating \\Plugin\\Comments\\View\\Themed\\Slate\\Elements and then copying all the contents of \\Plugin\\Comments\\View\\Elements to the new directory. However, this solution does not work .
  2. Copying the \\Plugin\\Comments\\View\\Elements\\comments directory to \\app\\View\\Themed\\Slate\\Elements . This solution is working fine. This solution works also if I copied to \\app\\View\\Elements .

I initialze the plugin from app/Config/bootstrap.php as follows:

CakePlugin::loadAll();

And from the controller as:

public function callback_commentsInitType() {

        return 'flat'; // threaded, tree and flat supported
    }

The following is a screen shot of the notice: 在此处输入图片说明

In addition when I try to access http://mywebsite.com/comments it returns error about Action CommentsController::index() could not be found. which is rendered in missy layout that mix my themed layout and the default CakePHP layout, the following shot demonstrates it:

在此处输入图片说明

In the CakePHP manual there is no any mention about copying view files of a plugin. It should work as it is! I don't know why the plugin missed its way to its elements?! How could I make this plugin interaction correctly with the theme view of the app?

If know well, you can create themed views for cakephp plugins. so after you copied this plugin into Plugins directory crate in your theme in your theme dir. Copy the content of plugin's View directory into: \\app\\View\\Themed\\Slate\\Plugin\\Comments

Cake php will use this directory for your plugin. Like this example \\app\\View\\Themed\\Slate\\Plugin\\Comments\\Elements\\comments\\flat.ctp

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