koenHuybrechts
koenHuybrechts

Reputation: 878

Put multiple segments of URL in 1 variable with Zend

For a new application I'd like to work with the URI to determine what content should be loaded. Nothing special so far ... But how can I let the slug have slash(es) in it and make sure Zend Framework sees them as 1 variable? ZF splits the requested URL in chunks where every part is the string between 2 slashed. Now I'd like to have all the parts in 1 variable to work with.

For Example:

/de/my/page

de > language
my/page > 1 variable

Any ideas?

Upvotes: 3

Views: 296

Answers (3)

Tomáš Fejfar
Tomáš Fejfar

Reputation: 11217

Custom router. Most flexible solution, but not the easiest one :(

Upvotes: 1

Jean-Christophe Meillaud
Jean-Christophe Meillaud

Reputation: 2071

Advice from Hari K is the best choice, but if you really want to keep your slash, you can work with a Zend_Controller_Router_Route_Regex to catch your parameter, you just need to find a good regexp, a simple example :

$routetotry = new Zend_Controller_Router_Route_Regex('([^/]+)/(.*)',
                    array(1 => 'de', 'controller' => 'someController', 'action' => 'someAction'),
                    array(1 => 'lang',2=>'my_variable_with_slash'),
                    '%s/%s'
);

$router->addRoute('routetotry', $routetotry);

Upvotes: 1

Hari K T
Hari K T

Reputation: 4254

Replace the slashes in the slug with someother value of your choice.

For example hyphen ( - ) or underscore ( _ ) .

Upvotes: 0

Related Questions