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.

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

报告相同问题?

悬赏问题

  • ¥60 不懂得怎么运行下载来的代码
  • ¥15 CST导出3D模型图为什么和软件显示不一样?
  • ¥15 加热反应炉PLC控制系统设计(相关搜索:梯形图)
  • ¥15 python 用Dorc包报错,我的写法和网上教的是一样的但是它显示无效参数,是什么问题
  • ¥15 经过滑动平均后的一维信号还原用什么结构好呢?
  • ¥15 指定IP电脑的访问设置
  • ¥30 matlab ode45 未发现警告,但是运行出错
  • ¥15 为什么devc++编译项目会失败啊
  • ¥15 vscode platformio
  • ¥15 代写uni代码,app唤醒