Yii Framework Forum: Adding url rules on the fly - Yii Framework Forum

Jump to content

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

Adding url rules on the fly Rate Topic: -----

#1 User is offline   manilodisan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 80
  • Joined: 17-September 09
  • Location:Bucharest

Posted 16 December 2009 - 04:34 PM

I have some modules which come with their own url rules so I push them using a class which is loaded. The class tries to set it's own rules for the module being loaded but it doesn't work:

Yii::app()->urlManager->rules = array_merge ( Yii::app()->urlManager->rules, array ( 	
	'aspinner/install' => 'aspinner/as_main/install' 
) );


If I put the same rule in the main config file the it works. Any idea why?

Here's a print after setting the rule on the fly from within the class:

CUrlManager Object
(
    [rules] => Array
        (
            [aspinner/install] => aspinner/as_main/install
        )

    [urlSuffix] => .html
    [showScriptName] => 1
    [appendParams] => 1
    [routeVar] => r
    [caseSensitive] => 1
    [cacheID] => cache
    [useStrictParsing] => 
    [_urlFormat:CUrlManager:private] => path
    [_rules:CUrlManager:private] => Array
        (
        )

    [_baseUrl:CUrlManager:private] => 
    [behaviors] => Array
        (
        )

    [_initialized:CApplicationComponent:private] => 1
    [_e:CComponent:private] => 
    [_m:CComponent:private] => 
)



As you can see, the rule is added but not counted as my application fails to use it.
0

#2 User is offline   Y!! 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 978
  • Joined: 18-June 09

Posted 17 December 2009 - 02:40 AM

You have to re-init the UrlManager after you add additional rules (because the actual processed rules are written to CUrlManager::$_rules).

Yii::app()->urlmanager->init();


Also before that you can just do:

Yii::app()->urlmanager->rules[] = array('aspinner/install' => 'aspinner/as_main/install');

0

#3 User is offline   manilodisan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 80
  • Joined: 17-September 09
  • Location:Bucharest

Posted 17 December 2009 - 05:43 AM

Yii::app()->urlmanager->init();

Thanks! That worked.
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