Yii Framework Forum: Camel Case Controller name causes InvalidRouteException - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Camel Case Controller name causes InvalidRouteException

#1 User is offline   zariphix 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 13-May 14

Posted 06 May 2015 - 09:10 AM

I have a custom controller named GetUserInfoController in GetUserInfoController.php and I have a url route rule : 'g' => getUserInfo/(id of action). But when visited the url my_host_name/g I receive an error of 404. I found InvalidRouteException in log of framework.

Then I read the code of framework.

I found that in function createControllerByID() of base/Module.php there is code

if (!preg_match('%^[a-z][a-z0-9\\-_]*$%', $className)) {
       return null;
}


it means my controller ID 'getUserInfo' cannot match the regular expression '%^[a-z][a-z0-9\\-_]*$%', because there a 'U' and 'I' in controller ID. It returns null, so creating controller failed.

I'm not sure is it OK? Could the regular expression be '%^[a-z][a-zA-Z0-9\\-_]*$%'?
0

#2 User is online   phtamas 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 646
  • Joined: 26-February 11
  • Location:Mezőtúr, Hungary

Posted 06 May 2015 - 10:07 AM

Just change the rule to:
 'g' => 'get-user-info/action-id',

I can't find the relevant part of documentation (maybe it doesn't exist at all) but the code above will work.
0

#3 User is offline   zariphix 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 13-May 14

Posted 07 May 2015 - 04:11 AM

Thanks, I have tried and it works.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

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