Flexible URLs?

Hi there - I’m new to Yii and have been reading all around the Yii docs to find a solution to my URL issue. I’m switching my site from Drupal to Yii - so far so good!

I currently have a bunch of URLs that all direct to the same controller, such as

u/828273

u/828273/node/2

u/828273/u

u/828273/d

u/828273/c/23

Each of these paths are handled in a similar way and then are handed off to sub actions based on the parts of the URL that come after the first two parts (these are auth links embedded in emails).

I’m wondering how I can implement this without making individual rules for each different possibility, since this could get very very long (there are tens of these, and are also other controllers that have a structures like this). Since the docs advise to keep the url rules at a minimum, I would like to be able to handle the secondary parts within my controller (or wherever is appropriate) and just have one main url rule - it would be great if I could just use the first one (u/blah) and then just get an array of the rest in the controller. Possible?

Another example is something like ‘review/create’ and ‘review/create/39’ which would pre-fill a certain form field.

Thanks!

Hi and welcome,

this is mainly a matter of creating the right regular expressions for your URL formats. If you’re not yet familiar with it, google it up. From what you described, i’d say you’ll need 2 or 3 rules. But it really depends on what kind of characters will be allowed.

Mike is right.

if you use urlManager with "path", Yii creates urls very similar to what you need.

if you have a controller called ‘u’, yii will call

public function actionIndex()

at the url ‘u/’.

You can add as parameters ad you want, like id and so on. So

You can write the action c, for create and the url u/c will activate actionC().

For passing id you can wirte after action, for example u/c/id/828273 will activate actionC(), with $_GET[‘id’]=828273

And so on.

With CurlManager you can format this base url in a different way, by using regular expressions