Yii Framework Forum: URL Manager - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

URL Manager confused Rate Topic: -----

#1 User is offline   jwallz 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 22-March 09

Posted 03 March 2011 - 10:09 PM

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?
0

#2 User is offline   ololo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 37
  • Joined: 23-January 11
  • Location:Minsk, Belarus

Posted 04 March 2011 - 09:22 AM

hi, it'll be something like this

// config
    'rules' => array(
        '/company/<companyName:\w+>' => 'company/view',
    ),

// in the controller
public function actionView($companyName) {
    // ... 


0

#3 User is offline   nicocin 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 29-November 10

Posted 04 March 2011 - 09:29 AM

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!
0

#4 User is offline   jwallz 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 22-March 09

Posted 04 March 2011 - 09:46 AM

View Postnicocin, on 04 March 2011 - 09:29 AM, said:

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'=>'companies/index',
'companies/<seo_url_name:\w+>'=>'companies/view',

then in my view action:

public function actionView()
{
if(isset($_GET['seo_url_name']))
{
$company=Post::model()->find('seo_url_name=?', array($_GET['seo_url_name']));
0

#5 User is offline   jwallz 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 22-March 09

Posted 04 March 2011 - 10:11 AM

View Postololo, on 04 March 2011 - 09:22 AM, said:

hi, it'll be something like this

// config
    'rules' => array(
        '/company/<companyName:\w+>' => 'company/view',
    ),

// in the controller
public function actionView($companyName) {
    // ... 




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

#6 User is offline   jwallz 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 22-March 09

Posted 04 March 2011 - 11:19 AM

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',
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users