当前位置: 首页>>代码示例>>PHP>>正文


PHP Mvc\Router类代码示例

本文整理汇总了PHP中Phalcon\Mvc\Router的典型用法代码示例。如果您正苦于以下问题:PHP Router类的具体用法?PHP Router怎么用?PHP Router使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Router类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: registerServices

 /**
  * Register the services here to make them general or register in the ModuleDefinition to make them module-specific
  */
 public function registerServices()
 {
     $di = new FactoryDefault();
     $loader = new Loader();
     $namespaces = [];
     $map = (require_once __DIR__ . '/../autoload_namespaces.php');
     foreach ($map as $k => $values) {
         $k = trim($k, '\\');
         if (!isset($namespaces[$k])) {
             $dir = '/' . str_replace('\\', '/', $k) . '/';
             $namespaces[$k] = implode($dir . ';', $values) . $dir;
         }
     }
     $loader->registerNamespaces($namespaces);
     $loader->register();
     /**
      * Register a router
      */
     $di->set('router', function () {
         $router = new Router();
         $router->setDefaultModule('frontend');
         //set frontend routes
         $router->mount(new FrontendRoutes());
         //
         return $router;
     });
     $this->setDI($di);
 }
开发者ID:adrianeavaz,项目名称:manager.io,代码行数:31,代码来源:Application.php

示例2: setDi

function setDi()
{
    $di = new FactoryDefault();
    $di['router'] = function () use($di) {
        $router = new Router();
        $router->setDefaultModule('mobimall');
        return $router;
    };
    $di['url'] = function () {
        $url = new UrlResolver();
        $url->setBaseUri('/');
        return $url;
    };
    $di['session'] = function () {
        $session = new SessionAdapter();
        // $session->start();
        return $session;
    };
    $loader = new Loader();
    $loader->registerNamespaces(array('Mall\\Mdu' => __DIR__ . '/../apps/mdu'));
    $sysConfig = (include __DIR__ . '/../config/sysconfig.php');
    $di['sysconfig'] = function () use($sysConfig) {
        return $sysConfig;
    };
    $loader->register();
    return $di;
}
开发者ID:nicklos17,项目名称:littlemall,代码行数:27,代码来源:index.php

示例3: modulesClosure

 public function modulesClosure(IntegrationTester $I)
 {
     $I->wantTo('handle request and get content by using single modules strategy (closure)');
     Di::reset();
     $_GET['_url'] = '/login';
     $di = new FactoryDefault();
     $di->set('router', function () {
         $router = new Router(false);
         $router->add('/index', ['controller' => 'index', 'module' => 'frontend', 'namespace' => 'Phalcon\\Test\\Modules\\Frontend\\Controllers']);
         $router->add('/login', ['controller' => 'login', 'module' => 'backend', 'namespace' => 'Phalcon\\Test\\Modules\\Backend\\Controllers']);
         return $router;
     });
     $application = new Application();
     $view = new View();
     $application->registerModules(['frontend' => function ($di) use($view) {
         /** @var \Phalcon\DiInterface $di */
         $di->set('view', function () use($view) {
             $view->setViewsDir(PATH_DATA . 'modules/frontend/views/');
             return $view;
         });
     }, 'backend' => function ($di) use($view) {
         /** @var \Phalcon\DiInterface $di */
         $di->set('view', function () use($view) {
             $view->setViewsDir(PATH_DATA . 'modules/backend/views/');
             return $view;
         });
     }]);
     $application->setDI($di);
     $I->assertEquals('<html>here</html>' . PHP_EOL, $application->handle()->getContent());
 }
开发者ID:phalcon,项目名称:cphalcon,代码行数:30,代码来源:ApplicationCest.php

示例4: initRouter

 protected function initRouter()
 {
     $this->getDI()->set('router', function () {
         $router = new Router();
         $router->setDefaultModule('hrm');
         return $router;
     });
 }
开发者ID:adrianeavaz,项目名称:manager.io,代码行数:8,代码来源:Application.php

示例5: mvcRouter

 private function mvcRouter()
 {
     //Register routing
     $router = new Router();
     $router->clear();
     foreach ($this->config('route') as $url => $route) {
         $router->add($url, $route->toArray());
     }
     return $router;
 }
开发者ID:serus22,项目名称:phalconz,代码行数:10,代码来源:Bootstrap.php

示例6: createFrom

 /**
  * @param array $routes
  * @return MvcRouter
  */
 public static function createFrom(array $routes) : MvcRouter
 {
     $router = new MvcRouter(false);
     $router->setUriSource(MvcRouter::URI_SOURCE_SERVER_REQUEST_URI);
     $router->removeExtraSlashes(true);
     foreach ($routes as $route) {
         $router->add($route['pattern'], $route['paths'] ?? null, $route['httpMethods'] ?? null, $route['position'] ?? MvcRouter::POSITION_LAST);
     }
     return $router;
 }
开发者ID:mamuz,项目名称:phalcon-application,代码行数:14,代码来源:Router.php

示例7: addRoutes

 public function addRoutes(Router $router)
 {
     $router->add('/' . $this->getApiRootUrl() . '(\\/?)', array('namespace' => $this->getApiControllerRootNamespace(), 'controller' => 'Index', 'action' => 'index'));
     $router->addGet('/' . $this->getApiRootUrl() . '/:controller/:params', array('namespace' => $this->getApiControllerRootNamespace(), 'controller' => 1, 'action' => 'show', 'params' => 2));
     $router->addGet('/' . $this->getApiRootUrl() . '/:controller', array('namespace' => $this->getApiControllerRootNamespace(), 'controller' => 1, 'action' => 'index'));
     $router->addPost('/' . $this->getApiRootUrl() . '/:controller', array('namespace' => $this->getApiControllerRootNamespace(), 'controller' => 1, 'action' => 'create'));
     $router->addOptions('/' . $this->getApiRootUrl() . '/:controller', array('namespace' => $this->getApiControllerRootNamespace(), 'controller' => 1, 'action' => 'options'));
     $router->addOptions('/' . $this->getApiRootUrl() . '/:controller/:params', array('namespace' => $this->getApiControllerRootNamespace(), 'controller' => 1, 'action' => 'options'));
     $router->addDelete('/' . $this->getApiRootUrl() . '/:controller/:params', array('namespace' => $this->getApiControllerRootNamespace(), 'controller' => 1, 'action' => 'delete', 'params' => 2));
     $router->addPut('/' . $this->getApiRootUrl() . '/:controller/:params', array('namespace' => $this->getApiControllerRootNamespace(), 'controller' => 1, 'action' => 'update', 'params' => 2));
 }
开发者ID:bullhorn,项目名称:fast-rest,代码行数:11,代码来源:ApiRoutes.php

示例8: registerServices

 /**
  * Register the services here to make them general or register in the ModuleDefinition to make them module-specific
  */
 protected function registerServices()
 {
     $di = new FactoryDefault();
     require '../../../autoloader.php';
     $loader = new Loader();
     /**
      * We're a registering a set of directories taken from the configuration file
      */
     $loader->registerDirs(array(__DIR__ . '/../apps/library/'))->register();
     $router = new Router();
     $router->setDefaultModule("frontend");
     //Registering a router
     $di->set('router', function () use($router) {
         return $router;
     });
     $this->setDI($di);
 }
开发者ID:silverwolfx10,项目名称:tcc-uhealth,代码行数:20,代码来源:index.php

示例9: zcms_load_frontend_router

/**
 * Load frontend router
 *
 * @param \Phalcon\Mvc\Router $router
 * @return \Phalcon\Mvc\Router
 */
function zcms_load_frontend_router($router)
{
    //Get frontend module
    $frontendModule = get_child_folder(APP_DIR . '/frontend/');
    $frontendModule = array_reverse($frontendModule);
    foreach ($frontendModule as $module) {
        $routerClass = 'Router' . ucfirst($module);
        $fileRoute = APP_DIR . "/frontend/{$module}/{$routerClass}.php";
        if (file_exists($fileRoute)) {
            require_once $fileRoute;
            if (class_exists($routerClass)) {
                $router->mount(new $routerClass());
            }
        }
    }
    return $router;
}
开发者ID:kimthangatm,项目名称:zcms,代码行数:23,代码来源:ZFunctions.php

示例10: __construct

 public function __construct(DiInterface $di)
 {
     parent::__construct(false);
     $this->clear();
     $this->removeExtraSlashes(true);
     $this->setUriSource(PhalconRouter::URI_SOURCE_SERVER_REQUEST_URI);
     $this->setDefaultAction('index');
     $this->setDefaultController('index');
     $this->setDI($di);
     $this->notFound(['controller' => 'error', 'action' => 'not-found']);
 }
开发者ID:tmquang6805,项目名称:phalex,代码行数:11,代码来源:Router.php

示例11: collectParams

 /**
  * @param Router\Route $route
  * @return array
  */
 private function collectParams(Router\Route $route)
 {
     $matches = $this->router->getMatches();
     $params = [];
     foreach ($route->getPaths() as $name => $position) {
         if (isset($matches[$position])) {
             $params[$name] = $matches[$position];
         }
     }
     return $params;
 }
开发者ID:theDisco,项目名称:phalcon-expressive,代码行数:15,代码来源:PhalconRouter.php

示例12: setUp

 /**
  * Sets the environment
  */
 public function setUp()
 {
     parent::setUp();
     $this->di->set('router', function () {
         $router = new PhRouter(false);
         $router->add('/admin/:controller/p/:action', array('controller' => 1, 'action' => 2))->setName('adminProducts');
         $router->add('/api/classes/{class}')->setName('classApi');
         $router->add('/{year}/{month}/{title}')->setName('blogPost');
         $router->add('/wiki/{article:[a-z]+}')->setName('wikipedia');
         $router->add('/news/{country:[a-z]{2}}/([a-z+])/([a-z\\-+])/{page}', array('section' => 2, 'article' => 3))->setName('news');
         $router->add('/([a-z]{2})/([a-zA-Z0-9_-]+)(/|)', array('lang' => 1, 'module' => 'main', 'controller' => 2, 'action' => 'index'))->setName('lang-controller');
         return $router;
     });
 }
开发者ID:lisong,项目名称:cphalcon,代码行数:17,代码来源:UnitTest.php

示例13: handle

 /**
  * registers module according to uri given
  *
  * @return bool true if module successfully loaded; <br />
  * 				false otherwise;
  */
 public function handle()
 {
     $boolReturn = false;
     $oLogger = $this->di->getFileLogger();
     $oPreRouter = new Router();
     $oPreRouter->add('/api(.*)', array('module' => 'api'));
     $oPreRouter->add('/regular(.*)', array('module' => 'regular'));
     $oPreRouter->add('/blind(.*)', array('module' => 'blind'));
     $oPreRouter->handle();
     $strModuleName = $oPreRouter->getModuleName();
     /**
      * @type Request $oRequest
      */
     $oRequest = $this->di->getRequest();
     if (array_key_exists($strModuleName, $this->knownModules)) {
         $this->app->registerModules(array($strModuleName => $this->knownModules[$strModuleName]));
         $this->app->setDefaultModule($strModuleName);
         $boolReturn = true;
         $oLogger->debug(__CLASS__ . ': ' . $oRequest->getURI() . ' leads to module: ' . $strModuleName);
     } else {
         if (!U::isLegacy()) {
             $strMsg = 'failed to load phalcon module';
         } else {
             $strMsg = 'loading old backend';
         }
         $oLogger->debug(__CLASS__ . ': ' . $strMsg . ' for "' . $oRequest->getUri() . '"');
     }
     return $boolReturn;
 }
开发者ID:rcmonitor,项目名称:abboom_phalcon_code_example,代码行数:35,代码来源:ModuleRouter.php

示例14: setUpDispatcher

 private function setUpDispatcher()
 {
     $this->dispatcher->setControllerName($this->router->getControllerName());
     $this->dispatcher->setActionName($this->router->getActionName());
     $this->dispatcher->setParams($this->router->getParams());
     $oDispatcherEventManager = new Manager();
     $oDispatcherEventManager->attach('dispatch:beforeDispatch', function (Event $oEvent, Dispatcher $oDispatcher, $data) {
         return false;
     });
     $this->dispatcher->setEventsManager($oDispatcherEventManager);
 }
开发者ID:rcmonitor,项目名称:abboom_phalcon_code_example,代码行数:11,代码来源:DefaultDispatcherTest.php

示例15: handle

 public function handle($path = null)
 {
     if ($path === null) {
         $path = $this->getRewriteUri();
     }
     // First attempt regular resolution.
     parent::handle($path);
     $router_route = $this->getMatchedRoute();
     if ($router_route !== NULL) {
         return $path;
     }
     $di = $this->getDI();
     $module_list = array_keys($di->get('phalcon_modules'));
     $path = trim($path, self::URI_DELIMITER);
     if ($path != '') {
         $path = explode(self::URI_DELIMITER, $path);
         if (in_array($path[0], $module_list)) {
             $this->_module = array_shift($path);
         }
         if (count($path) && !empty($path[0])) {
             $this->_controller = array_shift($path);
         }
         if (count($path) && !empty($path[0])) {
             $this->_action = array_shift($path);
         }
         if (count($path)) {
             $this->_params = $path;
         }
     }
     return $path;
 }
开发者ID:einstein95,项目名称:FAOpen,代码行数:31,代码来源:Router.php


注:本文中的Phalcon\Mvc\Router类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。