<?php //Create a group with a common module and controller $blog = new \Phalcon\Mvc\Router\Group(array('module' => 'blog', 'controller' => 'posts')); //Hostname restriction $blog->setHostName('blog.mycompany.com'); //All the routes start with /blog $blog->setPrefix('/blog'); //Default route $blog->add('/', array('action' => 'index')); //Add a route to the group $blog->add('/save', array('action' => 'save')); //Add another route to the group $blog->add('/edit/{id}', array('action' => 'edit')); //Add the group to the router $router->mount($blog);
// 路由命名(Naming Routes) $router->add("/posts/{year}/{title}", "Posts::show")->setName("show-posts"); $url->get(array("for" => "show-posts", "year" => "2012", "title" => "phalcon-1-0-released")); // 匹配回调函数(Match Callbacks) class AjaxFilter { public function check($uri, $route) { return $_SERVER['HTTP_X_REQUESTED_WITH'] == 'xmlhttprequest'; } } $router->add('...', array())->beforeMatch(array(new AjaxFilter(), 'check')); // 限制主机名(Hostname Constraints) $router->add('...', array())->setHostName('admin.company.com'); $router->add('...', array())->setHostName('([a-z+]).company.com'); Phalcon\Mvc\Router\Group::setHostName('blog.mycompany.com'); // 设置默认路径(Setting default paths) //Setting a specific default $router->setDefaultModule('backend'); $router->setDefaultNamespace('Backend\\Controllers'); $router->setDefaultController('index'); $router->setDefaultAction('index'); //Using an array $router->setDefaults(array('controller' => 'index', 'action' => 'index')); // 处理结尾额外的斜杆(Dealing with extra/trailing slashes) $router->removeExtraSlashes(true); // 没有找到路径(Not Found Paths) $router->notFound(array("controller" => "index", "action" => "route404")); $router->handle(); $di->set('router', function () { require __DIR__ . '/../app/config/routes.php';