I moved working plugin from /plugins/pluginname directory to /vendor/myname/pluginname
URL on which I call plugin controller is
http://domain.local/pluginname/index
Before moving from first directory to another, plugin was working as expected. I moved plugin to new directory to make it reusable for other cake PHP apps.
Plugin is installed by composer.
Why do I have message
"Error: Controller class Index could not be found.". All controllers
from plugin are not visible on app, throws the same error. Error is
thrown from line 79 from file
\vendor\cakephp\cakephp\src\Routing\Dispatcher.php
In main bootstrap.php file I put this line:
Plugin::load('MyName/PluginName', ['bootstrap' => false, 'routes' => true]);
Why plugin in vendor directory is not working in my case?
If plugin is installed by Composer, do not move it.
Whether it is installed at the plugin or vendor folder is determined by the author of the plugin.
If you need to fully load the Plugin in your bootstrap, simply use
Plugin::load('PluginName', ['bootstrap' => false, 'routes' => true]);
See http://book.cakephp.org/3.0/en/plugins.html#plugin-configuration
It will simply work regardless if Composer places it in vendor or plugins folder.
Most importantly, leave it in the folder that the author intended it to be in.
Lastly, check that your plugin is suitable for CakePHP 3.x
As for the url, you should expect to use /plugin-name/controller/action
See http://book.cakephp.org/3.0/en/plugins.html#plugin-controllers and I quote
If you want to access what we’ve got going thus far, visit /contact-manager/contacts
You can try by setting autoload variable true.Add below code in bootstrap.php, clear cache and then check.
Plugin::load('PluginName', ['autoload' => true]);
Related
I have just updated my composer and after that when i run my Yii2 application i got this error "Class dektrium\rbac\Module does not exist" i am using rbac in my application.
I checked desctrium\rabc directory there is no file with Module class. However i can see two new files RbacWebModule, RbacConsoleModule in that directoy.
I have a backup of my application on other server. so do i have to put my backup there to correct this error or is there any other solution. i can see in my vendor folder all other folders also get updated with composer update. So how to get rid of this error.
Thanks in advance.
This class has been renamed over a month ago. Since it's still beta I recommend to check for any major changes with every upgrade. Always follow the instruction.
Add rbac module to web application config file as follows:
...
'modules' => [
...
'rbac' => 'dektrium\rbac\RbacWebModule',
...
],
...
I installed tha cakephp Utils plugin via composer, and then I loaded all plugins in my bootstrap.php file, I added a field in my database model for the image path (cause I want to upload image profile using Uploadable), and then I add the following code I my model table:
$this->addBehavior('Utils.Uploadable', [
'foto_dir',
]);
but when I access the model I get the following error:
Utils.UploadableBehavior could not be found.
Make sure your plugin Utils is in the C:\wamp\www\siec2\plugins\ directory and was loaded.
Screenshot:
Please help.
Plugins installed with composer are stored inside the vendor folder. Please make sure, you have the Utils Plugin in the following folder /vendor/cakemanger/cakephp-utils
If so, check cakephp-plugins.php inside the vendor folder for this:
return [
'plugins' => [
...
'Utils' => $baseDir . '/vendor/cakemanager/cakephp-utils/'
]
];
Also make sure, you loaded the plugin in your bootstrap.php: Plugin::load('Utils');
See Plugins Section on CakeBook.
I've been looking at all the related questions of this topic and none of the solutions provided (usually App::import() ) have worked for me, maybe because I have a different configuration, which is the following:
I have a regular cake installation which loads components from an external folder (so outside this installation). That works perfectly, even for the component I'm trying to use now (it works fine until I try to load the Vendor class). This Vendor class I want to have it outside the Cake installation as well (same as with the components). This is how this installation looks:
[root]
.......[shared_resources]
......................................[CakePHP]
........................................................[Components]
..............................................................................MyCustomComponent.php
........................................................[Vendor]
....................................................................[MyVendor]
......................................................................................MyVendor.php
......[MySite]
................... [cakephp typical folder structure]
In my site's bootstrap.php file I have App::build(array('Controller/Component' => array(dirname(ROOT) . '/shared_resources/CakePHP/Component/'))); in order to be able to load that component in any controller, which works fine, any component I put in that folder loads and works without issues.
Now, I'm trying to load the MyVendor class in the MyCustom component, but I can't get it to work, no matter what I try I keep getting class not found errors when trying to instantiate it.
I've tried using php's and Cake's require(), import(), App::import() and App::uses() with all possible combinations of paths (absolute and relative) without any success, puttin them before the declaration of the component class and inside the method that actually uses the vendor class. The last one I've tried is App::import('Vendor', '/absolute/path/to/shared_resources/Vendor/MyVendor/MyVendor.php'); for example.
I've also tried using App::build(array( 'Vendor' => array(dirname(ROOT) . '/shared_resources/CakePHP/Vendor/'))); in the bootstrap file, like with the components.
I don't know what else to try, any help would be much appreciated!!!
Oh, I've check with PHP that the file Vendor class file exists in that path too.
According to your folder structure,
To access your MyVendor.php, you should write like this
App::import('Vendor', 'MyVendor', array('file' => 'MyVendor/MyVendor.php'));
For more information, read http://book.cakephp.org/2.0/en/core-utility-libraries/app.html
I've noticed some people mentioning a similar request for controllers and sometimes models, but I've been unable to find anything on arranging plugins in subfolders.
I want...
/app
/Plugin
/Modules
/Form
/Controller
/Gallery
/Controller
/SomeStandardPlugin
/Controller
..so that I can keep all the CMS functionality specific plugins separate.
I've tried:
CakePlugin::load('Form');
CakePlugin::load('Modules/Form');
CakePlugin::load('../Plugin/Modules/Form');
No matter which of the above I try, when I attempt to make use of the controller in one of the plugins, it says:
Error: FormsController could not be found.
Error: Create the class FormsController below in file: app\Controller\FormsController.php
(Which would be fine if I didn't want it in a plugin!)
The CookBook didn't mention anything about it either - is it just not supported or am I missing something?
FYI: I'm using CakePHP v2.2.3
The argument for CakePlugin::load is not a path
The first argument for this function, is the name of a plugin. This is the correct way to load a plugin:
CakePlugin::load('Name');
But it will only work if the plugin exists in a location configured using App::build
As such, to organize plugins into subfolders, it's necessary to declare all paths that contain a plugin:
// append app/Plugin/Modules to the path to look for plugins
App::build(array(
'Plugin' => array(
APP . 'Plugin/Modules'
)
));
Is it possible to load a single plugin from outside the cake root using App::build()?
If I do:
App::build(array(
'Plugin' => array('/full/path/to/plugin_dir/')
));
..I can load a whole directory of plugins but what if I only want to use one of them? Is this possible? (I get errors when using a path to the specific plugin directory).
(P.s. This is cake version 2.1)
From the bootstrap.php in a baked application:
CakePlugin::load('DebugKit'); //Loads a single plugin named DebugKit
You have to add the directory with the plugin in it via App::build() and then the plugin itself with the method above.
While using "App::build()" you are not "loading" all the files in there. You are defining the paths where cake searches for php to include in case it has to.
Nothing will be loaded if it is not need since Cakephp 2.0. Everythings is about lazy loading ^^
How this is, what you are searching for ;)