Yii Framework Forum: routes / modules / createUrl - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

routes / modules / createUrl Rate Topic: -----

#1 User is offline   thomas.mery 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 107
  • Joined: 04-January 09

Posted 27 April 2009 - 02:56 PM

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

returns

admin/admin/user/list

instead or returning the route I set up

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

but

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


0

#2 User is online   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,855
  • Joined: 04-October 08
  • Location:DC, USA

Posted 27 April 2009 - 03:37 PM

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'.
1

#3 User is offline   thomas.mery 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 107
  • Joined: 04-January 09

Posted 27 April 2009 - 04:25 PM

thanks for replying

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

$this->createUrl('user/show');

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

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

and I call

$this->createUrl('user/show')

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





0

#4 User is online   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,855
  • Joined: 04-October 08
  • Location:DC, USA

Posted 27 April 2009 - 04:40 PM

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

#5 User is offline   thomas.mery 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 107
  • Joined: 04-January 09

Posted 27 April 2009 - 05:11 PM

indeed I had ... a trailing slash

thanks a lot for pointing this out !

I'll be more careful

works as expected now

0

#6 User is offline   spidaboy7 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 19-April 12
  • Location:Rwanda,Kigali

Posted 23 September 2012 - 08:03 AM

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
array(
 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>
 94 
 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                 )); ?>


0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users