Пример #1
0
 /**
  * Create a new extended Phalcon group.
  * 
  * @param 	string   $prefix            
  * @param 	mixed    $paths             
  * @param 	callable $callback
  * @return  void 
  */
 public function __construct($prefix, $paths = null, callable $callback, $removeExtraSlashes = true)
 {
     parent::__construct($paths);
     $this->removeExtraSlashes = $removeExtraSlashes;
     $this->setPrefix($prefix);
     call_user_func($callback, $this);
 }
Пример #2
0
 public function __construct($config)
 {
     $this->controllerDefault = $config->router->controllerDefault;
     $this->actionDefault = $config->router->actionDefault;
     parent::__construct();
 }
Пример #3
0
$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('/');
$router->mount($frontend);
/**
 * Define routes for each module
 */
$modules = ['oauth', 'backend'];
foreach ($modules as $module) {
    $group = new Group(['module' => $module]);
    $group->setPrefix('/' . $module);
    $group->add('/:controller/:action/:params', array('controller' => 1, 'action' => 2, 'params' => 3));
    $group->add('/:controller/:int', ['controller' => 1, 'id' => 2]);
    $group->add('/:controller[/]?', ['controller' => 1]);
    $frontend->add('/:controller/:int/{slug:[a-z\\-]+}', ['controller' => 1, 'id' => 2, 'slug' => 3, 'action' => 'view']);
    $group->add('[/]?', array());
    $router->mount($group);
}
$router->add('/backend', ['module' => 'backend', 'controller' => 'dashboard']);
$router->add('/oauth/github/access_token', ['module' => 'oauth', 'controller' => 'login', 'action' => 'tokenGithub']);
$router->add('/oauth/google/access_token', ['module' => 'oauth', 'controller' => 'login', 'action' => 'tokenGoogle']);
$router->add('/oauth/facebook/access_token', ['module' => 'oauth', 'controller' => 'login', 'action' => 'tokenFacebook']);
$router->add('/questions', ['module' => 'frontend', 'controller' => 'posts']);
/**
 * @link https://docs.phalconphp.com/en/latest/reference/routing.html#match-callbacks
Пример #4
0
<?php

use Phalcon\Mvc\Router, Phalcon\Mvc\Router\Group as RouterGroup;
$router = new Router();
$router->add('/', ['controller' => 'country', 'action' => 'index']);
//About Countries Routes
$country = new RouterGroup(['controller' => 'country']);
$country->setPreFix('country');
$country->addGet('/', 'Country::index');
$router->mount($country);
//About Provinces Routes
$province = new RouterGroup(['controller' => 'province']);
$province->setPreFix('province');
$province->addGet('/', 'Province::index');
$province->addGet('/show/{id:[0-9]+}', 'Province::show');
$router->mount($province);
return $router;
Пример #5
0
 public function __construct($paths = null, DiInterface $di = null)
 {
     $module = isset($paths['module']) ? $paths['module'] : 'Default';
     parent::__construct(['module' => $module, $di]);
 }
Пример #6
0
 public function __construct($paths = null)
 {
     parent::__construct($paths);
 }
Пример #7
0
<?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;
Пример #8
0
    return $modules;
});
//遍历注册模块
$di->set('registerModules', function () use($di) {
    $modules = $di->get('modules');
    $regModules = [];
    foreach ($modules as $key => $val) {
        $regModules[$val] = ['className' => "Modules\\{$val}\\Module", 'path' => "../app/controllers/{$val}/Module.php"];
    }
    return $regModules;
});
// 加载每个模块里的路由文件
$di->set('router', function () use($di, $config) {
    $modules = $di->get('modules');
    $router = new Router();
    $adminRouterGroup = new RouterGroup();
    // 管理类分组
    $adminRouterGroup->setPrefix($config->application->adminPrefix);
    $frontendRouterGroup = new RouterGroup();
    //前端显示类分组
    $frontendRouterGroup->setPrefix($config->application->frontendPrefix);
    //    $apiRouterGroup = new RouterGroup();        //api,service类分组
    //    $apiRouterGroup->setPrefix($config->application->apiPrefix);
    $controllerPath = $config->application->controllersDir;
    // 一个路由分组的默认地址 这个路由分组里放的是显示网站数据的应用,称之为前台
    $frontendRouterGroup->add('/', ['namespace' => 'Modules\\Frontend\\Controllers', 'module' => 'Frontend', 'controller' => 'index', 'action' => 'index']);
    // 一个路由分组的默认地址 这个路由分组里放的是管理网站数据的应用,称之为后台
    $adminRouterGroup->add('/', ['namespace' => 'Modules\\Backend\\Controllers', 'module' => 'Backend', 'controller' => 'index', 'action' => 'index']);
    foreach ($modules as $key => $val) {
        if (file_exists($controllerPath . $val . "/Router.php")) {
            require_once $controllerPath . $val . "/Router.php";