URL without route and view?


(Tomasz) #1

Hi there,

I’ve been reading through URL part of guide, but since urlManager and beautifying URLs is one of my worst parts of Yii I was not able to find a solution to a problem that I have.

Is this possible in Yii to use URLs without route and view and only with GET params part in it?

In more details: My client wants to have a module on his website as similar as possible to RapidShare (for internal, private use only of course, I don’t think he’s planning another site like this! :) ). To solve it I need Yii to accept URLs like that:


http://example.com/rs/nnnnnn/fffff

where rs (or files or anything else) is a name of module or extension, nnnn is a unique number or hash and ffff is a filename, just like in Rapidshare, for example:


http://example.com/rs/2721632119/MGMaker-Movie-Nightmare.pdf

It finally can route to any controller and view. I only need to be able to process it. For example to FileController.php and get view in rs module, so actual route would be:


http://example.com/index.php?r=rs/file/get&id=2721632119&file_name=MGMaker-Movie-Nightmare.pdf

And to be honest, I have no damn idea how to achieve it? :(


(Matteo Falsitta) #2

Use urlFormat path, as explained in the definitive guide.

Then you can use some rules for hide the ‘id’ and ‘file_name’.

Give a try, and le us know if you need more help.


(Jacob Moen) #3

Maybe:


 'file/<action:\w+>/<id:\d+>/<file_name:\w+>' => 'rs/file/<action>',


(Tomasz) #4

Guys, thanks for all suggestions. I’ll indeed do some more research into Yii Definitve Guide and write here only if I get really, really stucked. I started this topic only because urlManager is probably the biggest mystery for me in Yii - and this is probably because I had always problems with regular expressions and related stuff.


(Jacob Moen) #5

Ask away - don’t be shy. :)

Just because it’s covered in the guide doesn’t mean it’s covered enough.