PHP Phalcon Wild card routing in multi module application -
update fixed solution.
foreach (array('core', 'backend' => array('alias' => 'admin'), 'api') $module => $options) { // if alias set utilize if (isset($options['alias']) && !empty($options['alias'])) { $module = $options['alias']; } // if module int $options contains module name if (is_int($module)) { $module = $options; } $group = new \phalcon\mvc\router\group(array( 'module' => $module, )); $group->setprefix('/' . (isset($options['alias']) ? $options['alias'] : $module)); // allow camel case controller , action name accessed via dashes $group->add('/([a-za-z\-]+)/([a-za-z\-]+)/:params', array( 'controller' => 1, 'action' => 2, 'params' => 3 ))->convert('action', function($action) { homecoming \phalcon\text::lower(\phalcon\text::camelize($action)); }); // mount grouping of routes module $router->mount($group); }
here router in app/bootstrap.php file
protected function router() { $this->di->set('router', function() { $router = new router(false); $router->setdefaults(array( 'module' => $this->config->router->default->module, 'controller' => $this->config->router->default->controller, 'action' => $this->config->router->default->action )); /* * defined routes traversed in reverse order until phalcon\mvc\router * finds 1 matches given uri , processes it, while ignoring rest. */ $frontend = new \phalcon\mvc\router\group(array( 'module' => 'frontend', )); // allow camel case controller , action name accessed via dashes $frontend->add('/([a-za-z\-]+)/([a-za-z\-]+)/:params', array( 'controller' => 1, 'action' => 2, 'params' => 3 ))->convert('action', function($action) { homecoming \phalcon\text::lower(\phalcon\text::camelize($action)); }); // mount grouping of routes frontend $router->mount($frontend); /** * define routes each module */ //foreach ($this->getmodules() $module => $options) { foreach (array('core', 'backend' => array('alias' => 'admin'), 'api') $module => $options) { $group = new \phalcon\mvc\router\group(array( 'module' => $module, )); $group->setprefix('/' . (isset($options['alias']) ? $options['alias'] : $module)); // allow camel case controller , action name accessed via dashes $group->add('/([a-za-z\-]+)/([a-za-z\-]+)/:params', array( 'controller' => 1, 'action' => 2, 'params' => 3 ))->convert('action', function($action) { homecoming \phalcon\text::lower(\phalcon\text::camelize($action)); }); // mount grouping of routes module $router->mount($group); } homecoming $router; }); }
here directory structure: http://pastie.org/9709545
my issues when go http://example.com/api/sms/send
gives me 404 page (hits frontend/module.php when should hitting api/v1.0.x/module.php)
when have smscontroller -> send action?
anyone know how route multi modules correctly?
thanks
php routing phalcon phalcon-routing
No comments:
Post a Comment