URL Manager - manually apply GET value?

Pretty simple question, I tried the rule:


'character/create' => 'character/edit/name?id=0'

Because if the ID == 0, that’s that page’s cue to create rather than modify. Problem is, Yii takes “name?id=0” as the actual action name, and doesn’t parse the GET parameter like the server would directly.

How can I specify that one specific GET-less user-end URL should be mapped to an action with one specific GET value?

Why not write an if in the action?


public function actionEdit($id= 0)

{

   if ($id==0)

   {

      Do something

   }

   else

   {

      Do something else

   }

}

that is not a question of urlmanager.

The action function has the conditional, naturally. And if I manually enter “/character/edit/name?id=0” into the address bar, it does run as expected. That’s not the problem. But I’m trying to use the URL manager to shorten/rename the URL, so that if I type in, “character/create”, with no GET, it goes to “/character/edit/name?id=0”, and parses the “?id=0” into GET just like the server normally would on its own.

try createUrl method -

‘character/create’ => Yii::app()->createUrl(‘character/edit/name’, array(‘id’=>‘0’));

That spits out a fatal error; Call to a member function createUrl() on a non-object. I’m thinking maybe Yii::app() doesn’t exist before the config file is done or something?

Did you try something like:




'character/create' => array('character/edit/name', 'defaultParams' => array('id' => 0))



Bingo, that seems to work! Much appreciated.