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.

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

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集