-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Action names, dashed to camelCase #284
Comments
You can add a listener to the dispatcher and transform the action before be dispatched: $di->set('dispatcher', function(){
//Create an event manager
$eventsManager = new Phalcon\Events\Manager();
//Attach a listener for type "dispatch"
$eventsManager->attach("dispatch", function($event, $dispatcher) {
$actionName = Phalcon\Text::camelize($dispatcher->getActionName());
$dispatcher->setActionName($actionName);
});
$dispatcher = new \Phalcon\Mvc\Dispatcher();
//Bind the eventsManager to the view component
$dispatcher->setEventsManager($eventsManager);
return $dispatcher;
}, true); |
Thank you very much! Continued to be impressed with Phalcon power and flexibility :) |
Hmm... Found that if i define action name with dash, it is not set in $dispatcher: $eventsManager->attach('dispatch', function($event, $dispatcher) {
echo '<pre>';
var_dump($dispatcher->getActionName());
}); url: /test/action
returns "action"
url: /test/test-action
returns NULL Perhaps i should also setup additional route or action parsing rules? |
Yes, you must add routes that allow dashes in the action part: $router = new Phalcon\Mvc\Router(false);
$router->add('/:controller', array(
'controller' => 1
));
$router->add('/:controller/([a-zA-Z\-]+)/:params', array(
'controller' => 1,
'action' => 2,
'params' => 3
)); |
A short and more clean version of this can be achieved in 0.8.0 using a conversor : $router = new Phalcon\Mvc\Router(false);
$router->add('/:controller', array(
'controller' => 1
));
$router->add('/:controller/([a-zA-Z\-]+)/:params', array(
'controller' => 1,
'action' => 2,
'params' => 3
))->convert('action', function($action) {
return Phalcon\Text::camelize($action);
}); |
Please re-open this if you still have questions about this |
Hi @phalcon I have an issue related to this one. Can you look at it? http://forum.phalconphp.com/discussion/2384/blank-page-on-for-some-actions#C8088 |
Base on @phalcon answer, use this route setting: (note $router->add('/:controller/([a-zA-Z\-]+)/:params', array(
'controller' => 1,
'action' => 2,
'params' => 3
))->convert('action', function($action) {
return lcfirst(Phalcon\Text::camelize($action));
}); |
I'm using phalcon 2.1.0r. Application based on Invo. |
I'm following this guide. my services_web.php
my routes.php
URL TEST: #2 : localhost/regular-wash-pack/detail-submit #3 : localhost/regular-wash-pack/detailSubmit Please help |
Currently if i will action like
it will be accessible only by url
I would like to have dashed names, where all words are divided by dashes:
Lowercase names for actions looks like better then camelCase in url address bar (just from my point of view).
Is it possible to use dashed names for controller actions in urls? Perhaps there is a global solution to change router logic, to transform all dashed action names into camelCase?
The text was updated successfully, but these errors were encountered: