Hey, that was just a test to see if those two routes were working, am I
right in assuming the members one worked and the posts one worked, but all
your others did not?

All you need to do is setup routes *before* the posts route to catch the
ones which are currently broken, you can specifically define them like
Router::connect('/pages/*', array('controller' => 'pages', 'action' =>
'display')); or maybe the method of doing :controller/:action would work
too.

The reason you're having these issues is that routes are executed from the
top down, so the first one to match is the one that is used. CakePHP
automatically detects routes like :controller/:action/:param, but your /*
route overrides this making this feature break. You need to specify the
routes which are being overwritten and probably do the /* one last.

Hope this helps

i.e.




On 3 January 2014 20:45, gonzela2006 <gonzela2...@gmail.com> wrote:

> But other links like /pages/display/about gave me 404 error as it routes
> to posts controller not pages controller.
>
> Thanks
>
>
> On Friday, January 3, 2014 10:07:23 PM UTC+2, Stephen S wrote:
>
>> The link you gave me is done a little differently to how you are doing it
>> now, all the post is introducing is a new method to parse the route itself.
>>
>> Normally you may have something like /posts/view/slug which may be public
>> function view($slug = null), then you may execute a query to find the first
>> post record which contained that exact slug and load the results into an
>> array. Mark is doing a similar search in his actual custom route file,
>> caching it, then passing that information to the controller so it doesn't
>> have to do that. He doesn't appear to mention the issue you are having,
>> unless I missed it, I'm afraid.
>>
>> Try this for me and see if it helps
>>
>> Router::connect(
>>     "/members/:plugin/:controller",
>>     array('action' => 'index', 'prefix' => members, members => true)
>> );
>> Router::connect(
>>     "/members/:plugin/:controller/:action/*",
>>     array('prefix' => members, members => true)
>> );
>> Router::connect(
>>     "/members/:controller",
>>     array('action' => 'index', 'prefix' => members, members => true)
>> );
>> Router::connect(
>>     "/members/:controller/:action/*",
>>     array('prefix' => members, members => true)
>> );
>> Router::connect('/*', array('controller' => 'posts', 'action' => 'view'));
>>
>> Then try to access /post-slug and /members/users/login and see what
>> happens.
>>
>>
>> On 3 January 2014 19:31, gonzela2006 <gonze...@gmail.com> wrote:
>>
>>> Hi Stephen,
>>>
>>> s members a prefix, or do you have a users method with login parameter,
>>>> or do you have that as a custom route?
>>>
>>> Yes, members is a prefix but the problem also exists with urls without
>>> prefix like /pages/display/about
>>>
>>> I found a post on Mark Story's blog that is talking about my problem but
>>> it was for CakePHP 1.3 how can I use it with CakePHP 2?
>>>
>>> http://mark-story.com/posts/view/using-custom-route-classes-in-cakephp
>>>
>>> Thanks
>>>
>>>
>>> On Friday, January 3, 2014 9:16:58 PM UTC+2, Stephen S wrote:
>>>
>>>>  A few things come to my mind off the top off my head.
>>>>
>>>> You could route your controller-action url's first, to catch the actual
>>>> links such as /members/users/login (is members a prefix, or do you have a
>>>> users method with login parameter, or do you have that as a custom route?)
>>>>
>>>> Then providing you did those routes correctly, the bottom route would
>>>> catch anything that didn't match the earlier ones, hopefully your post 
>>>> slug.
>>>>
>>>> Another idea would be to use a regular expression to match the pattern
>>>> of a "post-slug", if there are any distinguishing features this would be
>>>> much more effective. If not I would recommend doing something like this:
>>>>
>>>> /posts/post-slug
>>>> /blog/post-slug
>>>> /keyword/post-slug (i.e. if I was writing on a health care blog, I
>>>> would use /health/post-slug. This could produce something like
>>>> /health/top-10-diet-tips which holds the keyword health as well as the
>>>> slug.)
>>>>
>>>> It would be easier to avoid issues if you did it this way.
>>>>
>>>> HTH
>>>>
>>>> --
>>>> Kind Regards
>>>>  Stephen Speakman
>>>>
>>>  --
>>> Like Us on FaceBook https://www.facebook.com/CakePHP
>>> Find us on Twitter http://twitter.com/CakePHP
>>>
>>> ---
>>> You received this message because you are subscribed to the Google
>>> Groups "CakePHP" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to cake-php+u...@googlegroups.com.
>>> To post to this group, send email to cake...@googlegroups.com.
>>>
>>> Visit this group at http://groups.google.com/group/cake-php.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>
>>
>>
>> --
>> Kind Regards
>>  Stephen Speakman
>>
>  --
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
>
> ---
> You received this message because you are subscribed to the Google Groups
> "CakePHP" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to cake-php+unsubscr...@googlegroups.com.
> To post to this group, send email to cake-php@googlegroups.com.
> Visit this group at http://groups.google.com/group/cake-php.
> For more options, visit https://groups.google.com/groups/opt_out.
>



-- 
Kind Regards
 Stephen Speakman

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to