如何在 CakePHP 中加载自定义插件?
我正在为一个基于 CakePHP 的网站编写一个投票插件。如果我从它自己的 URL(例如 myapp.com/plugin/controller
)访问该插件,该插件可以很好地工作,但我需要从不同的页面调用它。我想将它作为一个小部件包含在每个页面中。
我正在寻找类似 $myplugin->renderPoll($pollId);
的方法,但我确实没有找到任何有关如何实例化 Polls 类的信息。我尝试使用 App::import
和 ClassRegistry::init
但没有成功。
有什么建议吗? 谢谢
I'm writing a poll plugin for a website based on CakePHP. The plugin works good if I access it from its own URL (eg. myapp.com/plugin/controller
) but I need to call it from different pages. I would like to include it as a widget in every page.
I'm looking for a method like $myplugin->renderPoll($pollId);
but I really didn't find any information about how to instantiate the Polls class. I tried with App::import
and ClassRegistry::init
with no luck.
Any suggestion ?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来您正在尝试创建某种
Helper
来创建民意调查交叉视图?我建议为该特定类创建一个Helper
。只需在plugins/plugin_name/views/helpers/foo.php
中创建一个帮助程序,然后在您需要的每个控制器(或在app_controller.php
中)中包含该帮助程序作为$helpers = array("PluginName.Foo");
在你的视图中,你应该能够通过调用使用
。foo.php
中定义的方法$foo->renderPoll($pollId)Looks like you are trying to create some sort of
Helper
to create poll cross views? I would suggest creating aHelper
for that particular class. Simply create a helper inplugins/plugin_name/views/helpers/foo.php
, and in each controller (or inapp_controller.php
) that you need it, include the helpers as$helpers = array("PluginName.Foo");
and inside your view, you should be able to use the methods defined infoo.php
by calling$foo->renderPoll($pollId)
.使用元素!它们是小块的演示代码,需要逐页重复,有时在布局中的不同位置重复。
查看此链接:http://book.cakephp.org/view/1081/Elements
我想这个链接解释了你需要的一切。
Use Elements! They're small blocks of presentation code that need to be repeated from page to page, sometimes in different places in the layout.
Check this link out: http://book.cakephp.org/view/1081/Elements
I guess this link explains everything you need.