I am trying to take advantage of the Custom URL Rule Classes in Yii r1.8
I am trying to take something that looks like orgs/view/id/24 and instead display the name of the org as identified by Name in the db (i.e. changing www.mysite.com/orgs/view/id/24 to www.mysite.com/jaysshop dynamically ). Unfortunately I am not getting it to work.
Here is my code:
<?php
class OrgsUrlRule extends CBaseUrlRule
{
public $connectionID = 'db';
public function createUrl($manager,$route,$params,$ampersand)
{
if ($route==='orgs/view/id') //even tried 'orgs/view' or 'orgs/index'
{
if (isset($params['Name']))
return $params['Name'];
else if (isset($params['Name']))
return $params['Name'];
}
return false;
}
public function parseUrl($manager,$request,$pathInfo,$rawPathInfo)
{
if (preg_match('%^(\w+)(/(\w+))?$%', $pathInfo, $matches))
{
}
return false;
}
}
?>
Ok mdomba, I get what you are saying but I thought this was a dynamic way of creating urls. According to the docs and included example of manufacturer/model that is what it appears to me. With all the orgs in my db I don’t want the users to see the full url of www.mysite.com/orgs/view/id/24. Instead www.mysite.com/jaysshop
Thanks for the further explanation mdomba. That does help my understanding of the url creation process but not the inability of having the urlManager rules handling what I want to accomplish.
Maybe I am just not understanding the capabilities of Custom URL Rule Classes. With this statement in the docs though
"For example, in a car dealer website, we may want to support the URL format like
`/Manufacturer/Model`, where `Manufacturer` and `Model` must both match some data in
a database table."
I read that as being what I want to accomplish.
Others have figured out how to accomplish what I want with a variable. Maybe I need to go that route then and assign a variable to my orgs.Name? Although I would rather stick to this added functionality in r1.8 if it does indeed support what I am after.