CakePHP 2.0 中的插件默认控制器
我正在努力让自定义插件与默认控制器一起使用:
例如,在 CakePHP 1.3 中,我可以创建一个用户插件并在其中创建一个 users_controller ,它会自动成为插件控制器,
我可以访问用户控制器中的方法users 插件通过:
/users/add
/users/edit/1
如果我在 CakePHP 2.0 中执行相同操作,我会收到以下错误:
Error: Users.AddController could not be found.
Error: Create the class AddController below in file: /home/richarda/www/test/cake_zero/www/app/Plugin/Users/Controller/AddController.php
我可以通过以下 url 访问它们:
/users/users/add
/users/users/edit/1
奇怪的是,默认索引操作按预期工作,即。我可以转到
/users
并可以从用户插件中的用户控制器查看索引视图。
2.0 文档中没有提及插件的默认控制器,此功能是否已被删除?
I'm struggling to get a custom plugin to work with a default controller:
e.g. in CakePHP 1.3 I could create a users plugin and create a users_controller in it which automatically becomes the plugins controller,
I could access the methods of the user controller in the users plugin via:
/users/add
/users/edit/1
If I do the same in CakePHP 2.0 I get the following errors:
Error: Users.AddController could not be found.
Error: Create the class AddController below in file: /home/richarda/www/test/cake_zero/www/app/Plugin/Users/Controller/AddController.php
I can access them at the following urls:
/users/users/add
/users/users/edit/1
Oddly, the default index action works as expected, ie. I can go to
/users
and can see the index view from the users controllers in the users plugin.
There is no mention of default controllers for plugins in the 2.0 docs, has this functionality been removed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
事实证明,CakePHP2.0 中插件的默认路由已被禁用,
这是我发布的票证: http://cakephp.lighthouseapp.com/projects/42648/tickets/2237-20-plugins-dont-have-a-default-controller#ticket-2237-3
解决方案是创建自定义路线:
现在就可以开始了。
希望这对某人有帮助。
Turns out default routing for plugins has been disabled in CakePHP2.0
Here's the ticket I posted: http://cakephp.lighthouseapp.com/projects/42648/tickets/2237-20-plugins-dont-have-a-default-controller#ticket-2237-3
The solution is to create a custom route:
And you're good to go.
Hope this helps someone.
我在 cake 2.2.0 中使用它,它适用于我的名为 admin 的插件。
希望您能将其应用到您的情况中。
Router::connect('/admin/', array('plugin'=>'admin','controller'=>'groups','action'=>'index'));
I use this in cake 2.2.0 and it works for my plugin called admin.
Hope you can apply it to your situation.
Router::connect('/admin/', array('plugin'=>'admin','controller'=>'groups','action'=>'index'));