In Cakephp 3.x, What is the Best Practice for Removing [Username] from a Plugin you install with composer?

断了今生、忘了曾经 提交于 2019-12-12 03:33:00

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!