createUrl() append and user friendly url

Good day everyone!

For example we have current route (pathInfo): "site/contact"

So if we call createUrl() from SiteController like this $this->createUrl("contact_done") we will have url "site/contact_done" it is very handy!


If we have urlManager rule like this:


then if we will call $this->createUrl("contact_done") we will have not "site/contact_done" but "/contact_done".

If there is a way to get url like in first case("site/contact_done") and not using full path but only one action name in createUrl() method?

Dear Friend,

This is what I am getting when I tried to simulate your scenario.

The controllerId:TestController

The actioniId:learn

The rule in urlManager:




echo $this->createUrl('learnMore');


The output of http://localhost/blog/index.php/learn

Thank you!

Try your example with not createUrl but with redirect() :)))

We must provide route in array then redirect method will call createUrl() in it.


and createUrl(‘learnMore’), works yes)

Just a stupid mistake.

Dear Friend,

redirect also works if you make a rule in urlManager in the following way,


I removed my previous rule