Yii Framework Forum: Question about urlManager - Yii Framework Forum

Jump to content

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

Question about urlManager Rate Topic: -----

#1 User is offline   micz 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 31
  • Joined: 05-June 09

Posted 16 February 2010 - 07:44 AM

I read guide to url manager. I have question is it possible to create rule for example:

'about_us' => 'site/pages' and add constant id to GET parameters for example

example.com/about_us would be equal to example.com/index.php?r=site/pages&id=4
0

#2 User is offline   andy_s 

  • Random Member Title
  • Yii
  • Group: Moderators
  • Posts: 1,526
  • Joined: 22-June 09
  • Location:Russia, Kostroma

Posted 16 February 2010 - 07:50 AM

Everything's possible with Yii :D

'about_us' => array('site/pages', 'defaultParams' => array('id' => 4)),

0

#3 User is offline   micz 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 31
  • Joined: 05-June 09

Posted 16 February 2010 - 07:57 AM

View Postandy_s, on 16 February 2010 - 07:50 AM, said:

Everything's possible with Yii :D

'about_us' => array('site/pages', 'defaultParams' => array('id' => 4)),



o thx :) i don't know how i missed it :)

but i have another problem with it, is it possible to do something like this

'about_us' => array('site/pages', 'defaultParams' => array('id' => 4)),
'our_partners' => array('site/pages', 'defaultParams' => array('id' => 5)),

because when i do something like that all URLs look like this

about_us?id=3,about_us?id=4 :(.
0

#4 User is offline   andy_s 

  • Random Member Title
  • Yii
  • Group: Moderators
  • Posts: 1,526
  • Joined: 22-June 09
  • Location:Russia, Kostroma

Posted 16 February 2010 - 08:10 AM

Try this property:
http://www.yiiframew...tchValue-detail

But in this situation I recommend you to create different actions "AboutUs", "OurPartners" etc.
0

#5 User is offline   andy_s 

  • Random Member Title
  • Yii
  • Group: Moderators
  • Posts: 1,526
  • Joined: 22-June 09
  • Location:Russia, Kostroma

Posted 16 February 2010 - 08:29 AM

Predicting your question about what to do, if you have many actions like AboutUs and OurPartners (too much rules and methods to write), I want to suggest a technique:

In UrlManager make a rule:

'<_a:(about_us|our_partners)>'=>'site/<_a>',
// or even a rule like this:
'<_a:([A-Za-z0-9_]+)>'=>'site/<_a>',


Then in SiteController define a method missingAction:

public function missingAction($actionId)
{
    switch ($actionId)
    {
        case 'about_us':  ...
        case 'our_partners':  ...
        ...
        default: // you can redirect or throw an exception there or call parent::missingAction($actionId).
    }
}

0

#6 User is offline   micz 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 31
  • Joined: 05-June 09

Posted 17 February 2010 - 05:15 AM

Thx for help that is good idea :). I didn't know missingAction function.
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