routes / modules / createUrl

hi all,

was working with routes and modules

and there is something I don't understand

I have a AdminModule

in which I have a UserController

I set up a route like this :

‘admin/user’ => ‘admin/user/list’

calling $this->createUrl(‘admin/user/list’) inside an AdminModule Controller or View



instead or returning the route I set up

I understand this is because the name of the module is prepended


I thought createUrl(url) would return the correct route that I set up

am I missing something ?

it's like routes are not connected with modules

or i'm just way off track ?

thanks in advance

When you are calling createUrl() inside a module, you don't need to add the module ID by yourself, since Yii will do this for you. If you insist to do this yourself, you can start the route with '/', i.e., '/admin/user/list'.

thanks for replying

I understand I can create a module url by just calling :


I think I still don't get why if I have a route like this :

‘admin/user’ => ‘admin/user/show/’,

and I call


inside a module I can't get the route I have set up : admin/user

so my question is

how do I make custom routes for modules ?

say I want : admin/user/show to be accessed by a route which pattern is : admin/user

I can setup something like this :

'admin/user' => 'admin/user/show',

and it works as calling admin/user redirects to admin/user/show

but calling createUrl('user/show') or createUrl('/admin/user/show')

won't return : 'admin/user'

Hope I'm clear

thanks in advance

You have an ending slash in your rule? It should be 'admin/user'=>'admin/user/show'

indeed I had … a trailing slash

thanks a lot for pointing this out !

I'll be more careful

works as expected now

Hello,i have a problem with url routing,i am using Yii-bootstrap extension,i am using drop down menu but their url arent directing directly to the module,for example


 86             'class'=>'bootstrap.widgets.TbMenu',

 87             'htmlOptions'=>array('class'=>'pull-right'),

 88             'items'=>array(

 89                 array('label'=>'Sign in', 'url'=>'/user/auth','visible'=>Yii::app()->user->isGuest),

 90                 '---',

 91                 array('label'=>'Profile', 'url'=>'#','visible'=>!Yii::app()->user->isGuest, 'items'=>array(

 92                     <b>array('label'=>'Settings', 'url'=>'/user/user/'),

 93                     array('label'=>'Logout', 'url'=>'/user/user/logout'),<b>


 95                 )),

 96             ),

 97         ),

 98     ),

 99 ));?>

arent directing to my user module,i am expecting something like /localhost/mysite/index.php/user/user and

/localhost/mysite/index.php/user/user/logout but i get this <b>localhost/user/user and localhost/user/user/logout</b>

but the strange thing with CMenu,i am getting what i expected with the same url,i am wondering if its not caused by the fact these links are submenu of main menu

here is my working menu with CMenu

<?php $this->widget('zii.widgets.CMenu',array(

131                         'items'=>array(

132                                 array('label'=>'Home', 'url'=>array('/site/index')),

133                                 array('label'=>'About', 'url'=>array('/site/page', 'view'=>'about')),

134                                 array('label'=>'Contact', 'url'=>array('/site/contact')),

135                                 array('label'=>'Login', 'url'=>array('//user/auth'), 'visible'=>Yii::app()->user->isGuest),

136                                 array('label'=>'Logout ('.Yii::app()->user->name.')', 'url'=>array('//user/user/logout'), 'visible'=>!Yii::app()->user->i    sGuest),

137                                 array('label'=>'My profile ', 'url'=>array('/user/user/'), 'visible'=>!Yii::app()->user->isGuest),

138                         ),

139                 )); ?>