Cphalcon: Route action and controller parameter inconsistencies

Created on 28 Oct 2018  路  9Comments  路  Source: phalcon/cphalcon

$router->add('...', [
    'controller' => 'my_controller' // MyController
    'action' => 'my_action' // my_action
]);
bug medium

Most helpful comment

Not going to be fixed/addressed in 3.x series. Adding this to 4.x

Thank you @scrnjakovic

All 9 comments

That's why I prefer to use MicroCollection - define everything manually.

$adminRoutes->get('/deconnexion', 'logout', 'admin_logout');

@stamster nonetheless, the fact that framework treats those two differently is an issue :)

Personally, I do not think it's a problem.

The controller is transformed because you have to use the PSR-4.
The action is not transformed because there is no standard for the use of camelCase or snakeCase.

It's up to the developer to do it right in my opinion.

@Ark4ne the two are closely related, so if we use one case for controller, we should stick with it when it comes to the action as well, regardless of the lack of the standard for the action.

Standards exist so that code we write is compatible and predictable. The lack of it doesn't mean we should stop caring. Having controller and action use two completely different cases introduces unexpected behavior, especially since it's not clearly mentioned in the docs.

But I could delete my whole answer and just say consistency.

Not going to be fixed/addressed in 3.x series. Adding this to 4.x

Thank you @scrnjakovic

Nope, thank you @niden.

@scrnjakovic If i get this right you want the framework to call your controller My_Controller
Unfortunatly I this will be possible, even in 4.x as 4.0 is aiming to be full PSR compliant, and class named My_Controller will violate:

you can't use underscores in Namespaces or classnames. They must be CamelCase with no seperations between words.

Also @Ark4ne PSR-1 4.3 enforces method naming conventions to lowerCamelCase.

The only bug is that the action does not get transformed to myAction @niden.

@JABirchall as @scrnjakovic said, the problem is the different behaviour. my_controller will be mapped to MyController and my_action will be mapped to a controller's method named my_action. Since @Ark4ne already pointed out the PSR guidelines for the class name, the most reasonable is to change the way Phalcon maps the action name.

Resolved

Was this page helpful?
0 / 5 - 0 ratings