PHP Phalcon Wild card routing in multimode application

UPDATE This has now been fixed with this solution.

    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);
        }

      

Here is my router in my 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
        ));

        /*
         * 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;
    });
}

      

Here is my directory structure: http://pastie.org/9709545

My problems: when I go to http://example.com/api/sms/send

it gives me 404 pages (frontend / Module.php is used when it should hit api / v1.0.x / Module.php)

When do I have an SmsController -> send action?

Does anyone know how to route multiple modules correctly?

thank

+3


source to share





All Articles