Named routings in rules

Hi everybody

In Yii 2.0 you can define specific rules for routings and access them with the createUrl()-Method.

Is it possible to create "named" routings, so they would be easier to generate the Urls without to know the defined rule?

Exmple (in config-file in "rules" of the UrlManager):


    'posts' => 'post/index', 


To generate a url of this rule i make Url::to([‘posts’]);

However is it possible to say that this rule should be named "mypost" and when i open in my browser /posts it should match with this rule?



    'name' => 'mypost',

    'pattern' => 'posts',

    'route' => 'post/index',


Its just a simple example, maybe it doesnt make sense in this example. I just want you to understand the idea behind.

I would like create now a Url like “Url::to(’@mypost’);” or so. Benefit: If the controller names etc changes i dont need to change everyver in my code the urls because i put them as “named” routes and so i just change it in my config-File once.

I hope you get my idea.

See this:

thx qiang!