0
votes

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?

2
you did enable the plugins, didnt you? - mark
Yes, plugins enabled in bootstrap.php with CakePlugin::loadAll(); - RichardAtHome

2 Answers

0
votes

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:

Router::connect('/users/:action', array('controller'=>'users', 'plugin'=>'users');

And you're good to go.

Hope this helps someone.

0
votes

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'));