Urlmanager Route Help

Hello! :)

My experience with yii has been pretty basic so far, but I’ve been using it on and off for two or three years now: and, I’m trying to learn about the urlManager next(never had to use it before ;D ).

In the yii guide there is an example of almost exactly what I want to try doing.

They show an example where using this url:


$this->createUrl('post/read',array('id'=>100))

would generate the url "post/100" based on this rule:


'post/<id:\d+>'=>'post/read'

I tried using that format but get a blank screen with my version of the rule:


'map/<id:\d+>'=>'map/getcurrentlocation'

…And my url:


$this->createUrl('map/getcurrentlocation',array('id'=>178))

…And when my urlManager rules look like this:




'rules'=>array(

                # my rules

                ''=>'map/index', // home page is maps list

                'map/<id:\d+>'=>'map/getcurrentlocation', // the rule I'm trying to get working

                # yii default rules

			'<controller:\w+>/<id:\d+>'=>'<controller>/view',

			'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',

			'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',

		),



If I change the rule I’m trying to get working to this:


'<controller:\w+>/<id:\d+>'=>'map/location'

I no longer get a blank screen initially, and the data loads as expected: but, the resulting url includes the action name like this:


map/getcurrentlocation/178

I was still expecting the url to result in this:


map/178

If someone could please point out why I get the blank screen using the original rule format(or let me know that it could be a number of things): and, why using my updated rule format results in having the action name in the generated url, that would be fantastic!

With everything same, could u try this:


$this->createUrl('map',array('id'=>178))

Unfortunately, that gives an action not found error, and putting the action name in instead results in the same lengthy url like:


map/getcurrentlocation/178

Try this


Yii::app()->urlManager->createUrl('map/10')

If this works, then your rule is right and generate such url by simply replacing 10 with variable.

Hmm, that seems to send the request to the actionView in my MapController. BTW I do appreciate your help Ujjwal, thanks!