Url Rules (Ability To Add A Value Before Controller/action, Etc)

Here’s my current url rule:

‘<client_id:\d+>/tickets/<action:\w+>/<id:\d+>’ => ‘tickets/<action>’,

What I’m trying to accomplish is having all the pages route like this:







So the 9999 would represent the actual client to who the data belongs to. The reason I’m doing this is because it’s easier to whether a client_id request matches the current data being looked up (permission wise)

I hope that makes sense. Any help accomplishing this with url rules is very much so appreciated.

So what’s the problem? Doesn’t it work?

I prefer to define module names explicitly to avoid ambiguity (module/controller and controller/action)







Order matters.

Ah okay, these seem to work. Thanks :) Next problem is getting the widgets to follow this url style. I guess I’m under the impression that Yii would build the url’s from the core widgets based on the url rules? Any idea why that might not be working?

Yii router is reversable, so if you define route something like this

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

and then use Yii’s native url builder, for example

<?= CHtml::link(array('/mycontroller/myaction', 'client_id' => 42), ...) ?>

you would get /42/mycontroller/myaction.

What’s the problem with widgets?

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

it maybe works, but is not correct. Part on right side of association should be a ROUTE, which means only <module>/<controller>/<action> or <controller>/<action>. Without any other GET parameters (like client_id).

Yeah, my bad, sorry.