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 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建