UPDATE 现在已使用此解决方案解决了这个问题。
foreach (array('core', 'backend' => array('alias' => 'admin'), 'api') as $module => $options) {
// If an alias is set use that
if (isset($options['alias']) && !empty($options['alias'])) {
$module = $options['alias'];
}
// If module is an int then $options contains the 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 and action name that will be accessed via dashes
$group->add('/([a-zA-Z\-]+)/([a-zA-Z\-]+)/:params', array(
'controller' => 1,
'action' => 2,
'params' => 3
))->convert('action', function($action) {
return \Phalcon\Text::lower(\Phalcon\Text::camelize($action));
});
// Mount a group of routes for some module
$router->mount($group);
}
这是我的app / Bootstrap.php文件中的路由器
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
));
/*
* All defined routes are traversed in reverse order until Phalcon\Mvc\Router
* finds the one that matches the given URI and processes it, while ignoring the rest.
*/
$frontend = new \Phalcon\Mvc\Router\Group(array(
'module' => 'frontend',
));
// Allow camel case controller and action name that will be accessed via dashes
$frontend->add('/([a-zA-Z\-]+)/([a-zA-Z\-]+)/:params', array(
'controller' => 1,
'action' => 2,
'params' => 3
))->convert('action', function($action) {
return \Phalcon\Text::lower(\Phalcon\Text::camelize($action));
});
// Mount a group of routes for frontend
$router->mount($frontend);
/**
* Define routes for each module
*/
//foreach ($this->getModules() as $module => $options) {
foreach (array('core', 'backend' => array('alias' => 'admin'), 'api') as $module => $options) {
$group = new \Phalcon\Mvc\Router\Group(array(
'module' => $module,
));
$group->setPrefix('/' . (isset($options['alias']) ? $options['alias'] : $module));
// Allow camel case controller and action name that will be accessed via dashes
$group->add('/([a-zA-Z\-]+)/([a-zA-Z\-]+)/:params', array(
'controller' => 1,
'action' => 2,
'params' => 3
))->convert('action', function($action) {
return \Phalcon\Text::lower(\Phalcon\Text::camelize($action));
});
// Mount a group of routes for some module
$router->mount($group);
}
return $router;
});
}
这是我的目录结构: http://pastie.org/9709545
我的问题是,当我去http://example.com/api/sms/send
时,它给了我一个404页面(当它应该打到api / v1.0.x / Module.php时命中前端/ Module.php)
当我有一个SmsController时 - >发送行动?
任何人都知道如何正确路由多个模块?
由于