Exemplo n.º 1
0
 public function testGroups()
 {
     Phalcon\Mvc\Router\Route::reset();
     $router = new Phalcon\Mvc\Router(false);
     $blog = new Phalcon\Mvc\Router\Group(array('module' => 'blog', 'controller' => 'index'));
     $blog->setPrefix('/blog');
     $blog->add('/save', array('action' => 'save'));
     $blog->add('/edit/{id}', array('action' => 'edit'));
     $blog->add('/about', array('controller' => 'about', 'action' => 'index'));
     $router->mount($blog);
     $routes = array('/blog/save' => array('module' => 'blog', 'controller' => 'index', 'action' => 'save'), '/blog/edit/1' => array('module' => 'blog', 'controller' => 'index', 'action' => 'edit'), '/blog/about' => array('module' => 'blog', 'controller' => 'about', 'action' => 'index'));
     foreach ($routes as $route => $paths) {
         $router->handle($route);
         $this->assertTrue($router->wasMatched());
         $this->assertEquals($paths['module'], $router->getModuleName());
         $this->assertEquals($paths['controller'], $router->getControllerName());
         $this->assertEquals($paths['action'], $router->getActionName());
         $this->assertEquals($blog, $router->getMatchedRoute()->getGroup());
     }
 }
Exemplo n.º 2
0
 public function testGroups()
 {
     $this->specify("Router Groups don't work properly", function () {
         \Phalcon\Mvc\Router\Route::reset();
         $router = new \Phalcon\Mvc\Router(false);
         $blog = new \Phalcon\Mvc\Router\Group(["module" => "blog", "controller" => "index"]);
         $blog->setPrefix("/blog");
         $blog->add("/save", ["action" => "save"]);
         $blog->add("/edit/{id}", ["action" => "edit"]);
         $blog->add("/about", ["controller" => "about", "action" => "index"]);
         $router->mount($blog);
         $routes = ["/blog/save" => ["module" => "blog", "controller" => "index", "action" => "save"], "/blog/edit/1" => ["module" => "blog", "controller" => "index", "action" => "edit"], "/blog/about" => ["module" => "blog", "controller" => "about", "action" => "index"]];
         foreach ($routes as $route => $paths) {
             $router->handle($route);
             expect($router->wasMatched())->true();
             expect($paths["module"])->equals($router->getModuleName());
             expect($paths["controller"])->equals($router->getControllerName());
             expect($paths["action"])->equals($router->getActionName());
             expect($blog)->equals($router->getMatchedRoute()->getGroup());
         }
     });
 }
Exemplo n.º 3
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;
Exemplo n.º 4
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);
Exemplo n.º 5
0
//获取单个活动信息
$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'));
//活动
Exemplo n.º 6
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;
     });
 }
Exemplo n.º 7
0
<?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;
Exemplo n.º 8
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;
Exemplo n.º 9
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;