Reputation: 837
I need route containing Both language parameter and slug in the url.
i.e http://localhost/demo/eng/home
Here "eng" is language name and "home" is slug name.
I have done following code in route.php
Router::connect('/:language/:action/*',array('controller' => 'homes'),array('language' => '[a-z]{3}'));
Router::connect('/:language/:slug/*', array('controller' => 'homes', 'action' => 'view'), array('language' => '[a-z]{3}','slug' => '[a-zA-Z0-9_-]+'));
Router::connect('/:slug',array('controller' => 'homes','action' => 'view'),array('slug' => '[a-zA-Z0-9_-]+'));
Also in view
Upvotes: 0
Views: 610
Reputation: 361
You have conflicted routes.
I am guessing that you are trying to pass a URL array like the following to HtmlHelper::link()
or HtmlHelper::url()
:
[
'controller' => 'homes',
'action' => 'view',
'language' => 'eng',
'slug' => 'press-release',
]
But this array matches not only /:language/:slug/*
but also /:language/:action/*
. Because both language
and action
are contained, and slug
matches *
as a named parameter.
And /:language/:action/*
appears before /:language/:slug/*
in your routes.php. If you define conflicted routes, the first defined route has higher priority. Thus, you get the URL /eng/view/slug:press-release
.
In conclusion, /:language/:action/*
should be removed or should be defined at least after /:language:/:slug/*
.
Upvotes: 1