示例#1
0
 /**
  * @dataProvider hostnamedRegexRoutesProvider
  */
 public function testHostnameRegexRouteGroup($actualHost, $expectedHost, $controller)
 {
     Phalcon\Mvc\Router\Route::reset();
     $di = new Phalcon\DI();
     $di->set('request', function () {
         return new Phalcon\Http\Request();
     });
     $router = new Phalcon\Mvc\Router(false);
     $router->setDI($di);
     $router->add('/edit', array('controller' => 'posts3', 'action' => 'edit3'));
     $group = new Phalcon\Mvc\Router\Group();
     $group->setHostname('([a-z]+).phalconphp.com');
     $group->add('/edit', array('controller' => 'posts', 'action' => 'edit'));
     $router->mount($group);
     $_SERVER['HTTP_HOST'] = $actualHost;
     $router->handle('/edit');
     $this->assertEquals($router->getControllerName(), $controller);
     $this->assertEquals($router->getMatchedRoute()->getHostname(), $expectedHost);
 }
示例#2
0
 public function testHostnameRegexRouteGroup()
 {
     $this->specify("Router Groups with regular expressions don't work properly", function ($actualHost, $expectedHost, $controller) {
         \Phalcon\Mvc\Router\Route::reset();
         $di = new \Phalcon\DI();
         $di->set("request", function () {
             return new \Phalcon\Http\Request();
         });
         $router = new \Phalcon\Mvc\Router(false);
         $router->setDI($di);
         $router->add("/edit", ["controller" => "posts3", "action" => "edit3"]);
         $group = new \Phalcon\Mvc\Router\Group();
         $group->setHostname("([a-z]+).phalconphp.com");
         $group->add("/edit", ["controller" => "posts", "action" => "edit"]);
         $router->mount($group);
         $_SERVER["HTTP_HOST"] = $actualHost;
         $router->handle("/edit");
         expect($router->getControllerName())->equals($controller);
         expect($router->getMatchedRoute()->getHostname())->equals($expectedHost);
     }, ["examples" => $this->hostnamedRegexRoutesProvider()]);
 }
示例#3
0
 public function testHostnameRegexRouteGroup()
 {
     Phalcon\Mvc\Router\Route::reset();
     $di = new Phalcon\DI();
     $di->set('request', function () {
         return new Phalcon\Http\Request();
     });
     $router = new Phalcon\Mvc\Router(false);
     $router->setDI($di);
     $router->add('/edit', array('controller' => 'posts3', 'action' => 'edit3'));
     $group = new Phalcon\Mvc\Router\Group();
     $group->setHostname('([a-z]+).phalconphp.com');
     $group->add('/edit', array('controller' => 'posts', 'action' => 'edit'));
     $router->mount($group);
     $routes = array(array('hostname' => 'localhost', 'controller' => 'posts3'), array('hostname' => 'my.phalconphp.com', 'controller' => 'posts'), array('hostname' => null, 'controller' => 'posts3'));
     foreach ($routes as $route) {
         $_SERVER['HTTP_HOST'] = $route['hostname'];
         $router->handle('/edit');
         $this->assertEquals($router->getControllerName(), $route['controller']);
     }
 }
示例#4
0
<?php

/*
 * Define custom routes. File gets included in the router service definition.
 */
$router = new Phalcon\Mvc\Router();
$router->add('/restore-password', ['controller' => 'signin', 'action' => 'restorePassword']);
$router->add('/new-password', ['controller' => 'profile', 'action' => 'newPassword']);
$router->add('/change-password', ['controller' => 'profile', 'action' => 'changePassword']);
$router->add('/language/{language}', ['controller' => 'language', 'action' => 'index']);
$userManagement = new \Phalcon\Mvc\Router\Group(['controller' => 'usermanagement']);
$userManagement->setPrefix('/manage-users');
$userManagement->add('', ['action' => 'index']);
$userManagement->add('/email', ['action' => 'sendEmail']);
$router->mount($userManagement);
return $router;
示例#5
0
<?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);
示例#6
0
$router->addPost('/activity/sign_up/', array('controller' => 'activity', 'action' => 'signUp'));
//获取单个活动信息
$router->addGet('/activity/{aid:\\d+}/user/{user_id:.*}', array('controller' => 'activity', 'action' => 'getActivityUser'));
//获取活动上家信息(用于扩散性活动)
$router->addGet('/activity/{aid:\\d+}/{user_id:.*}/puser', array('controller' => 'activity', 'action' => 'getActivityPuser'));
/*车辆信息*/
$router->addGet('/car_info/{user_id:.*}/{hphm:.*}', array('controller' => 'car', 'action' => 'getCarInfoByUserIdAndHphm'));
/*省市*/
//获取省份列表
$router->addGet('/provinces', array('controller' => 'province', 'action' => 'getProvinceList'));
//获取指定省份的城市列表
$router->addGet('/citise/{province_id:\\d+}', array('controller' => 'province', 'action' => 'getProvinceCitise'));
//上传文件
$router->addPost('/upload/file/{data_type:.*}', array('controller' => 'attachment', 'action' => 'upload'));
/*挪车提醒*/
$move_car = new \Phalcon\Mvc\Router\Group(array('controller' => 'movecar'));
$move_car->setPrefix('/move_car');
//挪车首页
$move_car->addGet('/', array('action' => 'index'));
$router->mount($move_car);
/*
其他tmp
*/
//保险20免一活动
//分享步骤 一
$router->addGet('/insurance_share', array('controller' => 'temp', 'action' => 'insuranceShare'));
//分享步骤 二
$router->addGet('/insurance_share/{p_user_phone:\\d+}', array('controller' => 'temp', 'action' => 'insuranceShare'));
$router->addGet('/insurance_share/{p_user_phone:\\d+}/{user_phone:\\d+}', array('controller' => 'temp', 'action' => 'insuranceShare'));
//活动描述
$router->addGet('/insurance_share/describe', array('controller' => 'temp', 'action' => 'insuranceShareDescribe'));
示例#7
0
 /**
  * Set the static router service
  *
  * @package     las
  * @version     1.0
  *
  * @return void
  */
 protected function router()
 {
     $this->_di->set('router', function () {
         $router = new \Phalcon\Mvc\Router(false);
         $router->setDefaults(array('module' => 'frontend', 'controller' => 'index', 'action' => 'index'));
         /*
          * 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'));
         $frontend->add('/:controller/:action/:params', array('controller' => 1, 'action' => 2, 'params' => 3));
         $frontend->add('/:controller/:int', array('controller' => 1, 'id' => 2));
         $frontend->add('/:controller[/]?', array('controller' => 1));
         $frontend->add('/{action:(buy|contact)}[/]?', array('controller' => 'static', 'action' => 'action'));
         $frontend->add('/');
         // Mount a group of routes for frontend
         $router->mount($frontend);
         /**
          * Define routes for each module
          */
         foreach (array('admin', 'doc') as $module) {
             $group = new \Phalcon\Mvc\Router\Group(array('module' => $module));
             $group->setPrefix('/' . $module);
             $group->add('/:controller/:action/:params', array('controller' => 1, 'action' => 2, 'params' => 3));
             $group->add('/:controller/:int', array('controller' => 1, 'id' => 2));
             $group->add('/:controller[/]?', array('controller' => 1));
             $group->add('[/]?', array());
             // Mount a group of routes for some module
             $router->mount($group);
         }
         $router->notFound(array('controller' => 'index', 'action' => 'notFound'));
         return $router;
     });
 }
<?php

/**
 * @todo переписать на класс, наследующий extends Phalcon\Mvc\Router\Group
 */
$adminRouter = new \Phalcon\Mvc\Router\Group(['namespace' => 'Admin\\Controllers', 'module' => 'admin', 'controller' => 'admin']);
$adminRouter->setPrefix('/admin');
$adminRouter->add('/shows', ['controller' => 'Shows', 'action' => 'similarShows'])->setName('admin-shows');
return $adminRouter;
<?php

/**
 * Socialveo Poll custom module routes
 *
 * @author      Socialveo.com Dev Team
 * @license     MIT License
 * @package     Poll
 * @since       1.0
 * @version     1.0
 */
$pollRouteGroup = new \Phalcon\Mvc\Router\Group(array('module' => 'poll', 'controller' => 'Poll', 'namespace' => 'Socialveo\\Poll\\Controllers'));
$pollRouteGroup->addPost('/v1/post/([a-z0-9-]{36})/submissions', array('action' => 'submission', 'post_uuid' => 1));
$router->groups['poll'] = $pollRouteGroup;
$router->mount($pollRouteGroup);
示例#10
0
<?php

/**
 * @todo переписать на класс, наследующий extends Phalcon\Mvc\Router\Group
 */
$autoAdminRouter = new \Phalcon\Mvc\Router\Group(['namespace' => 'Admin\\Controllers', 'module' => 'admin', 'controller' => 'admin']);
$autoAdminRouter->setPrefix('/admin');
$autoAdminRouter->add('', ['controller' => 'crud', 'action' => 'index'])->setName('admin');
$autoAdminRouter->add('/auto/{entity:[a-zA-Z]+}/{action:(edit|delete)}/:params', ['controller' => 'crud', 'entity' => 1, 'params' => 3])->setName('admin-action');
// такие действия должны быть только методом POST + проверка токенов
//$admin->addPost(
$autoAdminRouter->addPost('/auto/{entity:[a-zA-Z]+}/{action:(save|delete)}/:params', ['controller' => 'crud', 'entity' => 1, 'params' => 3])->setName('admin-action-post');
$autoAdminRouter->addGet('/auto/{entity}', ['controller' => 'crud', 'entity' => 1, 'action' => 'list'])->setName('admin-entity');
$autoAdminRouter->add('/login', ['action' => 'login'])->setName('admin-login');
$autoAdminRouter->add('/logout', ['action' => 'logout'])->setName('admin-logout');
return $autoAdminRouter;
示例#11
0
文件: core.php 项目: LWFeng/xnx
// 路由命名(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';
示例#12
0
<?php

$router = new \Phalcon\Mvc\Router(true);
$router->setDefaults(['namespace' => 'Controller', 'controller' => 'index', 'action' => 'index']);
$authGroup = new \Phalcon\Mvc\Router\Group(['namespace' => 'Controller', 'controller' => 'auth']);
$authGroup->addGet('/signin', ['action' => 'signIn'])->setName('signIn');
$authGroup->addGet('/signup', ['action' => 'signUp'])->setName('signUp');
$authGroup->addPost('/signin', ['action' => 'signInPost'])->setName('signInPost');
$authGroup->addPost('/signup', ['action' => 'signUpPost'])->setName('signUpPost');
$router->mount($authGroup);
return $router;
<?php

$router = new Phalcon\Mvc\Router();
//Create a group with a common module and controller
$blog = new Phalcon\Mvc\Router\Group(array('module' => 'blog', 'controller' => 'index'));
//All the routes start with /blog
$blog->setPrefix('/blog');
//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'));
//This route maps to a controller different than the default
$blog->add('/blog', array('controller' => 'about', 'action' => 'index'));
//Add the group to the router
$router->mount($blog);
示例#14
0
<?php

$miniAdminRouter = new \Phalcon\Mvc\Router\Group(['namespace' => 'MiniAdmin\\Controllers', 'module' => 'miniadmin', 'controller' => 'index']);
$miniAdminRouter->setPrefix('/miniadmin');
$miniAdminRouter->add('', ['controller' => 'index', 'action' => 'index'])->setName('mini-admin-index');
$miniAdminRouter->addGet('/create', ['controller' => 'index', 'action' => 'create'])->setName('mini-admin-create');
$miniAdminRouter->addPost('/create', ['controller' => 'index', 'action' => 'create'])->setName('mini-admin-save');
$miniAdminRouter->addGet('/edit/{id:[\\d]+}', ['controller' => 'index', 'action' => 'edit'])->setName('mini-admin-edit');
$miniAdminRouter->addPost('/edit/{id:[\\d]+}', ['controller' => 'index', 'action' => 'edit'])->setName('mini-admin-edit');
return $miniAdminRouter;
示例#15
0
 */
$router = new \Phalcon\Mvc\Router(FALSE);
$router->setDefaults(array('module' => 'frontend', 'controller' => 'index', 'action' => 'index'));
/*
 * 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'));
$frontend->add('/:controller/:action/:params', array('controller' => 1, 'action' => 2, 'params' => 3));
$frontend->add('/:controller/:int', array('controller' => 1, 'id' => 2));
$frontend->add('/:controller[/]?', array('controller' => 1));
$frontend->add('/{action:(buy|contact|terms)}[/]?', array('controller' => 'static', 'action' => 'action'));
$frontend->add('/');
// Mount a group of routes for frontend
$router->mount($frontend);
/**
 * Define routes for each module
 */
//foreach ($this->getModules() as $module => $options) {
foreach (array('backend' => array('alias' => \Phalcon\DI::getDefault()->getShared('config')->app->admin_uri), 'documentation' => array('alias' => 'doc')) as $module => $options) {
    $group = new \Phalcon\Mvc\Router\Group(array('module' => $module));
    $group->setPrefix('/' . (isset($options['alias']) ? $options['alias'] : $module));
    $group->add('/:controller/:action/:params', array('controller' => 1, 'action' => 2, 'params' => 3));
    $group->add('/:controller/:int', array('controller' => 1, 'id' => 2));
    $group->add('/:controller[/]?', array('controller' => 1));
    $group->add('[/]?', array());
    // Mount a group of routes for some module
    $router->mount($group);
}
$router->notFound(array('controller' => 'index', 'action' => 'notFound'));
return $router;