dongwen5336 2016-01-30 21:43
浏览 29
已采纳

我可以在带有别名的cakephp上加载插件吗?

Let's say that I install a plugin in CakePHP 2.x with name GmponosCakePlugin. This plugin would be under Plugins folder with Folder name GmponosCakePlugin.

To load the Plugin I need to do the following CakePlugin::load('GmponosCakePlugin');

Then if I need to use a Helper from this plugin I would have to use the following syntax GmponosCakePlugin.MyHelper inside my AppController in order to load the helper.

Is there any way I could have this plugin alias as Gmponos so I could load it as Gmponos.MyHelper

  • 写回答

1条回答 默认 最新

  • double820122 2016-01-30 23:58
    关注

    If you can't rename the folder, then the answer isn't necessarily no, but since there is no explicit plugin name aliasing functionality in CakePHP, all options you have are more or less "hacks".

    One option would be for example to register an additional fake plugin with the desired name, and a custom path that points to the actual plugin folder, like

    CakePlugin::load('Gmponos', array (
        'path' => APP . 'Plugin' . DS . 'GmponosCakePlugin' . DS
    ));
    

    This should work (not sure about possible side effects though), but it's kinda ugly. And it should be noted that this is in most cases required additionally to registering the normal plugin name, as in the plugin, code will refer to the actual plugin name.

    If it's your own plugin, and it is using composer, then changing the install folder name should be pretty easy via the installer-name extra option, which is the solution I'd prefer.

    https://github.com/composer/installers#custom-install-names

    You would ofcourse have to change possible plugin name references in the plugin code itself too.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?