CakePHP 1.3 插件快捷方式
我在网上搜索了很多,但找不到任何具体的解决方案。
在 CakePHP 1.3 中,与 1.2 不同的是,如果插件中有一个控制器,并且两者具有相同的名称,则可以通过“
http://cakeqs.org/eng/questions/view/ settings_up_magic_routes_for_plugins_in_cakephp_1_3
它已被删除,并且只有默认插件控制器中的“index”操作可以通过这种方式访问。
我考虑过在routes.php文件中添加额外的代码,并循环遍历应用程序中的所有插件,为以插件命名的控制器中的每个操作创建这样的路由,但这似乎不是正确的做法...
还有其他建议可以在 1.3 中实现此功能吗?或者至少有一些关于这个特定更改的非常具体的代码文档?我已经读过 1.3.0-RC4 公告中的一些内容,但还不够清楚..
谢谢
I searched a lot around the web but I couldn't find any specific sollution to this.
In CakePHP 1.3, different from 1.2, if you had a controller inside a plugin, and both had the same name, you could access through "<plugin>/<action>", and it would call the 'default' controller. But in 1.3, according to this:
http://cakeqs.org/eng/questions/view/setting_up_magic_routes_for_plugins_in_cakephp_1_3
It was removed, and only the 'index' action in the default plugin controller can be accessed this way.
I thought about adding extra code in my routes.php file, and loop through all the plugins in my app, making such routes for every action in the controllers named after the plugin, but it doesn't seem like it's the right thing to do...
any other suggestions to make this work in 1.3? or at least some very specific code documentation of this particular change? I've already read something in the 1.3.0-RC4 annoucement, but it was not clear enough..
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设有一个名为“test”的插件,您可以在 app/plugins/test/controller/test_controller.php 中执行类似的操作:
您还必须将以下内容添加到 app/config/routes.php:
完成此操作后,对 /test/another/one/two 的请求将在浏览器中正确呈现“一,二”,对 /test 的请求将显示“请求的插件索引”。
我认为这不是一个坏方法,插件消费者方面的麻烦最小,插件代码中只有一点点绒毛。
Assuming a plugin named "test", you could do something like this in app/plugins/test/controller/test_controller.php:
You'll also have to add the following to app/config/routes.php:
With this done, a request to /test/another/one/two will correctly render "one, two" in the browser, and a request to /test will display "Index of plugin requested."
I think this isn't a bad way to go, minimal fuss on the plugin consumer side, only a little bit of fluff in the plugin code.