3

更新现在这个解决方案已经解决了这个问题。

    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 时点击 frontend/Module.php)

当我确实有一个 SmsController -> 发送操作?

有人知道如何正确路由多个模块吗?

谢谢

4

0 回答 0