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!

BUT.

If we have urlManager rule like this:

‘contacts’=>‘site/contact’

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:




'learn'=>'test/learn',



learn.php




<?php

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.

$this->redirect(array(‘learnMore’));

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,




 '<action:\w+>'=>'test/<action>',



I removed my previous rule




'learn'=>'test/learn'