Reputation: 2214
Adding routes to perform a friendly url in my application, i found a obstacle...:
This is tha actual url:
http://website.local/search?filter[type]=1&filter[sub_type]=6&filter[city]=Sao Paulo
I need change to
http://website.local/property/house/big/Sao Paulo
Type and sub Type is ok,i make a parameter and dinamyc create a route for then, but city filter is a problem.
if i use:
Zend_Controller_Router_Route("'property/'.strtolower($type["name"]).'/' . strtolower($sub_type["name"])."/:city",'frontend','search','index',$params);",$params);
:city is forwarded, but like this:
array
'city' => string 'sao paulo' (length=9)
'module' => string 'frontend' (length=8)
'controller' => string 'search' (length=6)
'action' => string 'index' (length=5)
'filter' =>
array
'type' => string '1' (length=1)
'sub_type' => string '6' (length=1)
And i need to be this:
array
'module' => string 'frontend' (length=8)
'controller' => string 'search' (length=6)
'action' => string 'index' (length=5)
'filter' =>
array
'type' => string '1' (length=1)
'sub_type' => string '6' (length=1)
'city' => string 'sao paulo' (length=9)
Have any way route this!!
Help!
Upvotes: 0
Views: 555
Reputation: 46
I had the same problem and solved it like this:
$params = Zend_Controller_Front::getInstance()->getRequest()->getParams();
unset($params['module'], $params['controller'], $params['action'], $params['page']);
//collect multiple params
$multiple = array();
foreach($params as $key=>$value) {
if (is_array($value)) {
$multiple[$key]=$value;
unset($params[$key]);
}
}
if (!empty($multiple)) {
$multiple = "?".http_build_query($multiple);
} else {
$multiple="";
}
This is the URL code that is generated:
<a href="<?php echo $this->url(array_merge($params, array('page'=>$this->previous)), 'default') . $multiple; ?>">
Upvotes: 1