Reputation: 8947
I would like to add some general purpose parameters to the URL. E.g.:
http://example.com/user/join?ref=bazuka_007
or
http://example.com/comments/123?simpleAuthToken=29c1urnfu9fh42183c43h1hc43814h0c
in case I would like to track from where users are coming to my site or auto-auth them.
How to orginize two things:
Upvotes: 2
Views: 100
Reputation: 2267
For you first example you can specify router rules as follows:
'rules'=>array(
...
array('user/index/username/<username>', 'pattern'=>'user/<username:\w+>*'),
...
)
http://example.com/user/join?ref=bazuka_007
Will become:
http://example.com/user/join/ref/bazuka_007
nd get parameters will be
$_GET[username] = 'join';
$_GET[ref] = 'bazuka_007';
The second example can be made by analogy with the first.
UPD:
Also you can specify more common rules:
'rules'=>array(
...
array('<controller>/index/param/<param>', 'pattern'=>'<controller:\w+>/<param:\.+>*'),
...
)
UPD2:
I guess if you want to do common logic for all requests then you should implement the logic in base controller and extend all your controllers from it.
Also you can inplement beforeAction()
method in every controller wich will be invoked before an every action in controller.
Upvotes: 1