<?php use Phalcon\Mvc\Router; $router = new Router(); //Remove trailing slashes automatically $router->removeExtraSlashes(true); //main route $router->add("/", array('controller' => 'index', 'action' => 'index')); //GET VERB - GET ELEMENT //Get elemets of relationship. Ex: /department/2/user $router->addGet('/:controller/:int/([a-zA-Z0-9_-]+)', array('controller' => 1, 'action' => "list", 'id' => 2, 'relationship' => 3)); //Get one element. Ex: /user/2 $router->addGet('/:controller/:int', array('controller' => 1, 'action' => "get", 'id' => 2)); //Get all elements. Ex: /user $router->addGet('/:controller', array('controller' => 1, 'action' => "list")); //POST VERB - CREATE ELEMENT //Create a new element. Ex: /user $router->addPost('/:controller', array('controller' => 1, 'action' => "save")); //PUT VERB - UPDATE ELEMENT //Update a new element. Ex: /user $router->addPut('/:controller/:int', array('controller' => 1, 'action' => "save", 'id' => 2)); //DELETE VERB - UPDATE ELEMENT //Update a new element. Ex: /user $router->addDelete('/:controller/:int', array('controller' => 1, 'action' => "delete", 'id' => 2)); //not founded route $router->notFound(array('controller' => 'error', 'action' => 'page404')); $router->setDefaults(array('controller' => 'index', 'action' => 'index')); return $router;
/** * Phanbook : Delightfully simple forum software * * Licensed under The GNU License * For full copyright and license information, please see the LICENSE.txt * Redistributions of files must retain the above copyright notice. * * @link http://phanbook.com Phanbook Project * @since 1.0.0 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt */ use Phalcon\Mvc\Router\Group; use Phalcon\Mvc\Router; $router = new Router(false); $router->setDefaults(['module' => 'frontend', 'controller' => 'posts', 'action' => 'index']); $router->removeExtraSlashes(true); /* * 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 Group(['module' => 'frontend']); $frontend->add('/:controller/:action/:params', ['controller' => 1, 'action' => 2, 'params' => 3]); $frontend->add('/:controller/:int', ['controller' => 1, 'id' => 2]); $frontend->add('/:controller/:int/{slug:[a-z\\-]+}', ['controller' => 1, 'id' => 2, 'slug' => 3, 'action' => 'view']); $frontend->add('/posts/:int/{slug:[a-z\\-]+}', ['id' => 1, 'slug' => 2, 'action' => 'view']); $frontend->add('/:controller[/]?', ['controller' => 1]); $frontend->add('/blog/{id:[0-9]+}/{slug:[a-z\\-]+}', ['controller' => 'posts', 'action' => 'view']); $frontend->add('/questions/{id:[0-9]+}/{slug:[a-z\\-]+}', ['controller' => 'posts', 'action' => 'view']); $frontend->add('/questions/new', ['controller' => 'posts', 'action' => 'new']); $frontend->add('/');
<?php use Phalcon\Mvc\Router; $router = new Router(); //路由 $router->add('/', array('namespace' => 'Index\\Controllers', 'controller' => 'Index', 'action' => 'index')); $router->add('/(index|Index)/:controller/:action/:params', array('namespace' => 'Index\\Controllers', 'controller' => 2, 'action' => 3, 'params' => 4)); $router->add('/(App|app)/:controller/:action/:params', array('namespace' => 'App\\Controllers', 'controller' => 2, 'action' => 3, 'params' => 4)); $router->add('/(Agent|agent)/:controller/:action/:params', array('namespace' => 'Agent\\Controllers', 'controller' => 2, 'action' => 3, 'params' => 4)); $router->notFound(array("namespace" => 'System\\Controllers', "controller" => "Error", "action" => "error404")); $router->setDefaults(array('namespace' => 'Index\\Controllers', 'controller' => 'Index', 'action' => 'index')); return $router;
<?php use Phalcon\Mvc\Router\Group; use Phalcon\Mvc\Router; $router = new Router(false); $router->setDefaults(['controller' => 'tests', 'action' => 'index']); $router->removeExtraSlashes(true); $prefix = '/' . VERSION . '/'; //tests $tests = new Group(['controller' => 'tests']); $tests->setPrefix($prefix . 'tests'); $tests->addGet('', ['action' => 'index']); $tests->addGet('/{id:[0-9]+}', ['action' => 'view']); $tests->addPost('/new', ['action' => 'new']); $tests->addPut('/{id:[0-9]+}', ['action' => 'update']); //task $tasks = new Group(['controller' => 'task']); $tasks->setPrefix($prefix . 'tasks'); $tasks->addGet('', ['action' => 'index']); $tasks->addGet('/{id:[0-9]+}', ['action' => 'view']); $tasks->addPost('/new', ['action' => 'new']); $tasks->addPut('/{id:[0-9]+}', ['action' => 'update']); //token $token = new Group(['controller' => 'token']); $token->setPrefix($prefix . 'token'); $token->add('', ['action' => 'index']); //mount $router->mount($token); $router->mount($tests); $router->mount($tasks); return $router;
public function setDefaults(array $defaults) { return parent::setDefaults($defaults); }