URL Manager

i’m trying to do a simple url in the form of controller and seo friendly title, ie:

www.somedomain.com/company/general-electric

i want the request mapped to the company Controller’s View action where i’ll take the seo-friendly company name - general-electric and query against my company table’s seo-friendly-url column for a match

what would the pattern be for this in the url mamanger?

hi, it’ll be something like this




// config

    'rules' => array(

        '/company/<companyName:\w+>' => 'company/view',

    ),


// in the controller

public function actionView($companyName) {

    // ... 




This should work:

‘company/<name:\w+>’=>‘company/view’,

Inside the actionView() method of your CompanyController use $_GET[‘name’] to get the company name.

Check out the Guide. It’s explained pretty well!

that’s exactly what i tried but no luck. I get a system generated 404 saying it can’t find the requested action ‘company-name’. Meaning it’s trying to map the company name to an action.

i have:

‘rules’=>array(

            'companies'=&gt;'companies/index',


            'companies/&lt;seo_url_name:&#092;w+&gt;'=&gt;'companies/view',

then in my view action:

public function actionView()

{

    if(isset(&#036;_GET['seo_url_name']))


    {


        &#036;company=Post::model()-&gt;find('seo_url_name=?', array(&#036;_GET['seo_url_name']));

thanks I tried that but no luck. I get a 404 error: The system is unable to find the requested action "general-electric".

Got it. The problem was with the regular expression \w+. It only matches on alpha numeric characters. When i changed my rule to this it started working: ‘companies/<seo_url_name:[a-zA-Z0-9-]+>’=>‘companies/view’,