Hey, i’ve been trying to create a custom rule class extending ‘CBaseUrlRule’ that pulls a page up based on the custom seoURL that is stored within a database.
Can anyone show/explain an example of how to implement this?
My URL’s at the moment are like: .../pages/view/id/5
Within the database I have stored the custom seoURL column.
How I want the url’s to look: .../home (home being the seoURL stored within the database)
public function createUrl($manager,$route,$params,$ampersand)
{
if($route==='pages/view')
{
if (isset($params['seoURL']))
return $params['seoURL'];
}
return false; // this rule does not apply
}
public function parseUrl($manager,$request,$pathInfo,$rawPathInfo)
{
var_dump($pathInfo);
if(preg_match('%^[a-z0-9\-]+$%', $pathInfo, $matches))
{
var_dump($pathInfo);
$seoURL=$matches[0];
$command=Yii::app()->{$this->connectionID}->createCommand();
$result=$command->select('seoURL')->from('Pages');
$result->where('seoURL=:seoURL', array(':seoURL'=>$seoURL));
$result = $result->queryRow();
if(!empty($result))
{
$_GET['seoURL']=$result['seoURL'];
return 'pages/view';
}
}
return false; // this rule does not apply
}
Going to /pages/view/id/5 - goes to the homepage
Yet /home - throws ‘Error 400 Your request is invalid.’
I have stuck a var_dump within the parseUrl function and the path gets dumped when going through /pages/view/id… but nothing when just the seoURL
Unsure, sort of knew to PHP, trying to get to grips with everything still.