tags:

views:

130

answers:

1

I have a dashboard with a series of widgets. Per specification, the widgets need to be buried under a /widgets/ directory.

So I have added the following to my routes.php

Router::connect('/widget/:controller/:action/*', array());

But I seem to be running into trouble on widget/links/ and widget/links/view/1

I am new to CakePHP, but this doesn't seem all that impressive. I have yet to find anything in the Book or by search. So any help is appreciated.

Thanks.

A: 

Well...at the risk of stating the obvious...your route starts with /widget/, but you indicate that you're trying to access it via a plural URI (/widgets/). That's a problem. If that's just a typo, it would help to know what error you're seeing when you "run into trouble".

UPDATE:

Yes that was a typo. I corrected it. The error that appears for widget/links/ is: Error: WidgetController could not be found. It appears my index/default route is the main problem.

Given that information, it appears that CakePHP thinks that widget is your controller. Cake processes routes top down and finds the first one that matches. Ensure that you don't have a route above this one that looks something like /:controller/... or any other route above this one that starts with a variable.

Rob Wilkerson
Yes that was a typo. I corrected it.The error that appears for widget/links/ is: Error: WidgetController could not be found.It appears my index/default route is the main problem.
Jason McCreary
I don't have any other routes than the default page routes. Please keep in mind this is only for the index action when access from `/widget/controller_name`. You are right in that it assumes widget is the controller and is trying to use controller_name as the action. Clearly that is not the desired behavior. I am tempted to add a `Router::connect('/widget/:controller/', array('action' => 'index'));`
Jason McCreary
Then the presence of the trailing slash (/) in your routing statement may be the problem (as before, judging by the URI/routing combination in your comment). Routing can be pretty picky. You may have to provide 2 routes in order to handle both conditions.
Rob Wilkerson
I ultimately had to name the routes as mine was too vague. It the end it looked something like this `Router::connect('/widget/links/:action/*', array('controller' => 'links', 'action' => 'index'));`
Jason McCreary