Camel Case Controller name causes InvalidRouteException

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 [color="#FF0000"]’%^[a-z][a-zA-Z0-9\\-_]*$%’[/color]?

1 Like

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.

1 Like

Thanks, I have tried and it works.

1 Like