I installed a Theme (cakephp-adminlte-theme) via Plugin, located under: vendor/maiconpinto/cakephp-adminlte-theme
Now, i have created a Default-Page for the Admin-User. This is located under: src/Template/Layout/admin.ctp
This works correctly, but the admin.ctp includes a file called “nav-top.ctp” via element()-Methode.
Now, i created a file “nav-top.ctp” under: src/Template/Admin/Element/nav-top.ctp
But the file will not load …
I searched for this Issue, and located the incorrect Path-Order in: vendor/cakephp/cakephp/src/View/View.php
When i output the content of $paths, then it returned the following:
[
(int) 0 => ‘/vendor/maiconpinto/cakephp-adminlte-theme/src\Template’,
(int) 1 => ‘\src\Template’,
(int) 2 => ‘\vendor\cakephp\cakephp\src\Template’
]
I want the second Element on Position one, so that the following result will be returned:
[
(int) 0 => ‘\src\Template’,
(int) 1 => ‘/vendor/maiconpinto/cakephp-adminlte-theme/src\Template’,
(int) 2 => ‘\vendor\cakephp\cakephp\src\Template’
]
This path search order is how it’s supposed to work. A main use for plugins is to provide themes, as you’ve got here, and a theme really only works if it overrides the default views.
But there’s not enough information here to know whether this is actually your problem. The src/Template/Layout/admin.ctp is something you have created, right? How, specifically, are you trying to reference the nav-top element? And when you say “the file will not load”, do you mean that it’s not loading any such element at all, or it’s loading the one from the adminlte theme instead of yours?
The File src/Template/Layout/admin.ctp was created by me, correct.
The File nav-top.ctp is included via <?php echo $this->element('nav-top'); ?> in src/Template/Layout/admin.ctp.
The Method loads the nav-top.ctp from AdminLTE-Theme, located under:
‘/vendor/maiconpinto/cakephp-adminlte-theme/src\Template’
First, I don’t think anything is ever going to find src/Template/Admin/Element/nav-top.ctp by calling $this->element('nav-top'). Nothing in the call there is indicating that it should look in your Admin folder, and the directory structure seems wrong anyway.
Second, based on this setup, it’s always going to load the nav-top.ctp from the AdminLTE theme.
I think the solution to both is to reorganize things slightly. Assuming that you only need your version to be used in your admin layout, move your the file to src/Template/Element/Admin/nav-top.ctp, and call it with $this->element('Admin/nav-top') in your layout.
the Method $this->element('nav-top'); calls the Methode $this->_getElementFileName($name, $pluginCheck); from vendor/cakephp/cakephp/src/View/View.php.
This Method in turn calls $this->_paths($plugin);
The Method $this->_paths($plugin); returned a Array to _getElementFileName() with following content
On Row later, in the Method _getElementFileName you can see a call to the Method _getSubPaths wich returned the following array:
Now both arrays have been traversed. At the same time, file_exists() checks if the file exists.
The point remains that if it returned directories in the order that you think it should, then no plugin would ever be able to override a base implementation, and the ability to do is pretty key to how many plugins operate. This is not a CakePHP bug, in other words, it’s a problem with your implementation.