Hello,
I’m trying to set up a custom URL class, almost identical to what is described in the docs here, on a Yii 1.1.13 site.
<?php
class BasicUrlRule extends CBaseUrlRule
{
public function createUrl($manager,$route,$params,$ampersand)
{
if($route==='search/basic') {
if(isset($params['s1'], $params['s2'])) {
return $params['s1'] . '/' . $params['s2'];
}
}
return false; // this rule does not apply
}
public function parseUrl($manager,$request,$pathInfo,$rawPathInfo)
{
if (preg_match('/^([\w\s-]+)(\\/([\w\s-]+))?(\\/page-([\d]+))?$/', $pathInfo, $matches)) {
$seo = new Seo();
if($seo->isValid($matches[1], $matches[3])) {
$_GET['s1'] = $matches[1];
$_GET['s2'] = $matches[3];
if(isset($matches[5])) {
$_GET['results_page'] = $matches[5];
}
return 'search/basic';
}
}
return false; // this rule does not apply
}
}
The routing works great, I can visit /foo/bar, /foo/bar/page-2, /foo/bar/page-3, etc. and the parameters are passed as expected.
The problem is with the CLinkPager widget, which fails to build the proper links and instead just returns, for example on /foo/bar, /search/basic?s1=foo&s2=bar[&results_page=n]. On inspection I can see BasicUrlRule::createUrl being called, but $route is “foo/bar” where I’d expect it to be “search/basic”, and $params is always empty. I haven’t extended or modified any portion of CLinkPager or the other pagination classes. All my other routes are done using urlManager rules in config/main.php, and I have had no problems with pagination for those routes.
Any clues as to what I’m missing? Thanks.