Routes and urlManager

I’m trying to make the best use of the urlManager class, defining some routes, but I don’t find exhaustive guides to understand how the route writing system works. Any guide? Thank you

So the one in the Guide is insufficient?

If only it had a few more examples, for example I have a couple of rules but one like this:
<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>

:\w+ = ???
\d+ = ???

Here is an example of how I use it: ‘admin/id:\d+/view’ => ‘admin/view’,

Those are regular expressions. D+ means any number of digits, d means one digit.

For example ‘foo/id:\d+’ would match “foo/1” and “foo/42” but not “foo/bar”

w/w+ means characters… For example “foo/bar”
s/s+ means all symbols as well, “foo/bar-foo” (the - )

The rule above would match all routes with 3 segments, where 2 are strings with characters a-Z and the last is a number. It will then initiate the controller and it’s action.

Foo/bar/4 would call your FooController with actionBar and inject the parameter id with the value 4

thanks @Anubarak I use it without the special characters, I was doomed to see routes work up to number 9 :unamused: and the characters < and > what do they mean? What does shutting ID in or out of these changes?
where can I learn more about this rule of special characters (regular expression) ?

Thank you

Then the chars “<” and “>” what for ? you use them without. Thanks

When you declare a route like
'foo/bar' => 'some-action'
Your action is only called when someone visits www.example.com/foo/bar

When you would like to implement all possible routes of your site exactly like this, you would have thousands of routes depending on your project.
Furthermore if you would like to display certain entries in your database (detail view) you like to point a url directly to that one. Thus you use dynamic routes

'foo/<id:\d+>' => 'some-action'

This one will trigger your controller action when foo/1foo/99999 and so in is called. By using <> you are telling yii “attantion, this is a dynamic route. Match whatever fits”

The word you are writing between the brackets is the name of the variable that is injected into your controller action. For example you have access to

public function actionSomething(int $id)

Id will be your url param.

When you define the route via <helloWorld>
You will receive function actionFoo($helloWorld)

Yes, I created a file called routes and this is how I declare the routes.

'admin' => 'admin/index',
'admin/create' => 'admin/create',
'admin/<id:\d+>/update' => 'admin/update',
'admin/<id:\d+>/view' => 'admin/view',

Thanks @luismanoel12 for suggestion, and then include the file in the config / web? right ?

Thanks @Anubarak one question if I realize that I need an additional parameter for an action, should I update the route? Is there a directiva to take them all regardless of their name?