When filtering by “cat”(first rule) all its working but when I try to filter by province (2nd rule) I’m getting the value of parameter “cat” from the first rule. Does anybody know how to fix this? Thanks.
Thanks for your fast reply and for your observation, now I figured out, however it’s first time when I met this kind of problem. Basically i have a filter sidebar for search, when the user press on the filter link a new param will be appended to the url through a custom function. Before posting here i tried to use a rule like “<page>/<q:.?>/” this works but the url will looks like: http://localhost/mywebsite/pagename/search-string/cat/category-name-here/ or http://localhost/mywebsite/pagename/search-string/province/province-name-here/ do you have any idea how could i get rid of the “cat” or “province” from url?
Here is my view code for generating the categories filters:
// we use filter by category only if the cat param is not set
if (empty($_GET['cat'])) {
echo '<ul>';
foreach ($counts as $k => $count) {
$name = Categories::model()->findByPk($k)->name . ' (' . $count . ')';
$slug = Categories::model()->findByPk($k)->slug;
$url = add_url_param(array('cat' => $slug . '-' . $k));
echo '<li>';
echo CHtml::link($name, $url);
echo '</li>';
}
echo '</ul>';
}
// we use filter by province only if the province param is not set
if (empty($_GET['province'])) {
echo '<ul>';
foreach ($counts as $k => $count) {
$name = Province::model()->findByPk($k)->name . ' (' . $count . ')';
$slug = strtolower(Province::model()->findByPk($k)->name);
$url = add_url_param(array('province'=>$slug .'-'. $k));
echo '<li>';
echo CHtml::link($name, $url);
echo '</li>';
}
echo '</ul>';
}
Then in my helper functions file i have a simple function add_url_param for creating the url:
// add params to url
function add_url_param($addparams = array()) {
$route = Yii::app()->urlManager->parseUrl(Yii::app()->getRequest());
$params = $_GET;
//we remove the pagination param
if (isset($params['page'])) {
unset($params['page']);
}
foreach($addparams as $k => $val){
$params[$k] = $val;
}
$url = Yii::app()->createUrl('/' . $route, $params);
return $url;
}