Monday, August 30, 2010

Re: Router::connect() not behaving as expected in 1.3?

Not sure what order you had things in, but order is important. So, you
should be able to get things working by putting these two in the
following order:

Router::connect('/blog/:action/*',
Router::connect('/blog/*', array('controller'=>'news_articles'));

Obviously, the /blog/* will catch all occurrences, including stuff in
the other routing call. I am surprised, though, that the second call
should be necessary. Assuming your controller includes a view() action
and the /blog/* call doesn't include any action information (as your
example shows), there should be no reason why everything else
shouldn't work as advertised.

On Aug 26, 4:29 pm, SacoDesign <sign...@sacodesign.com> wrote:
> Thanks for the response.  I still cannot get the entire directory to
> respond as a controller without 2 router::connect() calls.  I removed
> the 'action'=>'index' as suggested.
>
> Has anyone else experienced this issue?  I removed every route from my
> routes.php and tried the following:
>
> Router::connect('/blog*', array('controller'=>'news_articles'));
> = missing 'BlogController' error; doesn't work for any request
> starting with /blog/
>
> Router::connect('/blog/*', array('controller'=>'news_articles'));
> = /blog/ -> shows index (working)
> = /blog/view/1/ -> shows index; should show view()
>
> Router::connect('/blog/:action/*',
> array('controller'=>'news_articles'));
> = /blog/ -> missing 'BlogController' error
> = /blog/view/1/ -> working
>
> On Aug 25, 1:46 pm, DragonFlyEye <dragonflyey...@gmail.com> wrote:
>
> > That all looks correct, and it would be the same in 1.2. You might
> > write the following, though:
>
> > Router::connect('/blog*', array('controller' => 'news_articles'));
>
> > That would push all requests for the /blog directory to the right
> > controller, then you can create the actions you want and they'll get
> > filled in automatically since you didn't specify a pseudo-route for
> > each one (which might get complicated).
>
> > Cricket's right, though: by putting the pseudo route :action in there
> > and then assigning the action 'index,' you're basically pushing every
> > single request with a second (but no third) subdirectory in the URL to
> > the same action. Seems like it's a bit inefficient?
>
> > On Aug 25, 9:05 am, SacoDesign <sign...@sacodesign.com> wrote:
>
> > > Hello,
>
> > > I'm upgrading my app from 1.2 to 1.3.  I have several custom routes
> > > setup like so:
> > >Router::connect('/blog/:action/*',
> > > array('controller'=>'news_articles', 'action'=>'index'));
>
> > > This works fine, except for when the url is only /blog/.  In that case
> > > I get a "cannot find blog controller" error.  Is this by design, or a
> > > bug?
>
> > > I can get it working by adding another route for:
>
> > >Router::connect('/blog', array('controller'=>'news_articles',
> > > 'action'=>'index'));
>
> > > but that seems wrong.
>
> > > Thanks,
>
> > > -Kevin Wentworth
>
>

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: