问题
When you install a plugin with composer, by default it puts it into ROOT/vendor/[username]/[plugin-name]. This also updates ROOT/vendor/cakephp-plugins.php with something like
return [
'plugins' => [
'[UserName]/[PluginName]' => $baseDir . '/vendor/[username]/[plugin-name]/'
]
];
This apparently also makes it so that your plugin's namespace should be something like.
namespace [Username]\[PluginName]\Controller;
And when you do a redirect (as an example) you refer to it with something like...
$this->redirect(['plugin' => '[Username]/[PluginName]', 'controller' => '[Controller]', 'action' => 'index']);
What is the best practice for removing [Username] from when you reference a plugin that you install with composer?
回答1:
The best practice is simply to remove your username from the autoload parameter in your plugin's composer.json file.
It looked like this::
"autoload": {
"psr-4": {
"Username\\PluginName\\": "src"
}
},
It should look like this
"autoload": {
"psr-4": {
"PluginName\\": "src"
}
},
来源:https://stackoverflow.com/questions/35611502/in-cakephp-3-x-what-is-the-best-practice-for-removing-username-from-a-plugin