當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Router::add方法代碼示例

本文整理匯總了PHP中Phalcon\Mvc\Router::add方法的典型用法代碼示例。如果您正苦於以下問題:PHP Router::add方法的具體用法?PHP Router::add怎麽用?PHP Router::add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Phalcon\Mvc\Router的用法示例。


在下文中一共展示了Router::add方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: 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

示例2: 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

示例3: testRoutes

 /**
  * @dataProvider routesProvider
  *
  * @param $arRoute
  * @param $strUri
  * @param $strClassName
  */
 public function testRoutes($arRoute, $strUri, $strClassName)
 {
     $this->router->add($arRoute['route'], $arRoute['parameters'])->setName($arRoute['name']);
     $this->router->handle($strUri);
     $boolMatched = $this->router->wasMatched();
     $this->assertTrue($boolMatched, 'failed to match ' . $strUri);
     $strRouteName = $this->router->getMatchedRoute()->getName();
     $this->assertEquals($arRoute['name'], $strRouteName, 'matched wrong route');
     $this->setUpDispatcher();
     $this->dispatcher->dispatch();
     $strControllerClassName = $this->dispatcher->getControllerClass();
     $this->assertEquals($strClassName, $strControllerClassName, 'wrong controller class name');
 }
開發者ID:rcmonitor,項目名稱:abboom_phalcon_code_example,代碼行數:20,代碼來源:DefaultDispatcherTest.php

示例4: addRoute

 /**
  * {@inheritdoc}
  */
 public function addRoute(Route $route)
 {
     // TODO allow named parameters through options.
     // TODO allow usage of :controller, :action, etc.
     // TODO allow using prefixes
     if ($this->router->wasMatched()) {
         throw new Exception\RuntimeException('Route was already matched.');
     }
     // Necessary for phalcon not to alter the original middleware.
     $middleware = $route->getMiddleware() . '\\MockController::mockAction';
     $r = $this->router->add($route->getPath(), $middleware, $route->getAllowedMethods());
     $r->setName($route->getName());
 }
開發者ID:theDisco,項目名稱:phalcon-expressive,代碼行數:16,代碼來源:PhalconRouter.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: 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();
     $loader = new Loader();
     /**
      * We're a registering a set of directories taken from the configuration file
      */
     $loader->registerDirs(array(__DIR__ . '/../apps/library/'))->register();
     //Registering a router
     $di->set('router', function () {
         $router = new Router();
         $router->setDefaultModule("frontend");
         $router->add('/:controller/:action', array('module' => 'frontend', 'controller' => 1, 'action' => 2));
         $router->add("/login", array('module' => 'backend', 'controller' => 'login', 'action' => 'index'));
         $router->add("/admin/products/:action", array('module' => 'backend', 'controller' => 'products', 'action' => 1));
         $router->add("/products/:action", array('module' => 'frontend', 'controller' => 'products', 'action' => 1));
         return $router;
     });
     $this->setDI($di);
 }
開發者ID:boiler256,項目名稱:mvc,代碼行數:23,代碼來源:index.php

示例8: 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

示例9: setUp

 public function setUp()
 {
     parent::setUp();
     $this->router = new Router();
     $this->router->add('/api/web/v1/:controller', array('module' => 'api', 'action' => 'index', 'controller' => 1))->setName('single_controller');
     $this->router->add('/api/web/v{version}', array('module' => 'api', 'action' => 'index', 'controller' => 'index'))->setName('simple_version');
     $this->router->add('/api/web/v{major:[0-9]{1,2}}\\.{minor:[0-9]{1,2}}', array('module' => 'api', 'action' => 'index', 'controller' => 'index'))->setName('syntax_version');
     $this->router->add('/api/web/v{major:[0-9]{1,2}}\\.{minor:[0-9]{1,2}}/:controller/:action', array('module' => 'api', 'action' => 4, 'controller' => 3))->setName('syntax_version_action_controller');
     $this->router->add('/api/mobile/v{major:[0-9]{1,2}}\\.{minor:[0-9]{1,2}}/:controller/:action/:params', array('module' => 'api', 'action' => 4, 'controller' => 3, 'params' => 5))->setName('syntax_version_action_controller_parameters');
     $this->router->add('/api/mobile/v{major:[0-9]{1,2}}\\.{minor:[0-9]{1,2}}/:controller/:action/:int', array('module' => 'api', 'action' => 4, 'controller' => 3, 'id' => 5))->setName('syntax_version_action_controller_id');
     $this->router->add('/api/{media}/v{major:[0-9]{1,2}}\\.{minor:[0-9]{1,2}}/:controller/:action/:int', array('module' => 'api', 'action' => 5, 'controller' => 4, 'id' => 6))->setName('media_syntax_version_action_controller_id');
     $arRoutes = $this->router->getRoutes();
     /**
      * @type Router\Route $oRoute
      */
     foreach ($arRoutes as $oRoute) {
         $this->routes[] = $oRoute->getPattern();
     }
 }
開發者ID:rcmonitor,項目名稱:abboom_phalcon_code_example,代碼行數:19,代碼來源:RouterMatchesTest.php

示例10: 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

示例11: add

 public function add($pattern, $paths = null, $httpMethods = null)
 {
     $_route = $pattern;
     $name = null;
     if ($_route instanceof \Phalcon\Mvc\Router\Route) {
         $pattern = $_route->getPattern();
         $paths = $_route->getPaths();
         $httpMethods = $_route->getHttpMethods();
         $name = $_route->getName();
     }
     if ($httpMethods != null && $name != null) {
         return parent::add($pattern, $paths)->via($httpMethods)->setName($name);
     } elseif ($httpMethods != null) {
         return parent::add($pattern, $paths)->via($httpMethods);
     } elseif ($name != null) {
         return parent::add($pattern, $paths)->setName($name);
     } else {
         return parent::add($pattern, $paths);
     }
 }
開發者ID:skullab,項目名稱:thunderhawk,代碼行數:20,代碼來源:Router.php

示例12: createDependencies

 /**
  * @return $this
  */
 public function createDependencies()
 {
     $dependency = new FactoryDefault();
     $dependency->set('db', function () {
         return $this->getDatabase();
     });
     $dependency->set('router', function () {
         $router = new Router(false);
         $routes = Routes::get();
         foreach ($routes as $group => $controllers) {
             foreach ($controllers as $controller) {
                 $router->add($controller['route'], ['namespace' => "App\\Controllers\\{$group}", 'controller' => $controller['class'], 'action' => 'run'], $controller['method']);
             }
         }
         $router->notFound(['namespace' => 'PhRest\\Controllers', 'controller' => 'Missing', 'action' => 'run']);
         return $router;
     });
     $dependency->set('view', function () {
         return new View();
     }, true);
     $this->setDI($dependency);
     return $this;
 }
開發者ID:alevikzs,項目名稱:phrest,代碼行數:26,代碼來源:Web.php

示例13: addRoute

 /**
  * add a new route
  *
  * @param PhRouter $router
  * @param $route
  * @param $params
  * @return PhRouter\RouteInterface
  */
 public function addRoute(PhRouter &$router, $route, $params)
 {
     $route = $router->add($route, $params);
     return $route;
 }
開發者ID:adrianeavaz,項目名稱:manager.io,代碼行數:13,代碼來源:Router.php

示例14: initRouter

 /**
  * Initializes the router
  *
  * @param array $options
  */
 protected function initRouter($options = array())
 {
     $config = $this->di['config'];
     $this->di['router'] = function () use($config) {
         // Create the router without default routes (false)
         $router = new PhRouter(true);
         // 404
         $router->notFound(array("controller" => "index", "action" => "notFound"));
         $router->removeExtraSlashes(true);
         foreach ($config['routes'] as $route => $items) {
             $router->add($route, $items->params->toArray())->setName($items->name);
         }
         return $router;
     };
 }
開發者ID:hacktm15,項目名稱:CityBox,代碼行數:20,代碼來源:bootstrap.php

示例15: Router

<?php

use Phalcon\Mvc\Router;
$router = new Router();
$router->add("/:controller/:action/:params", array('controller' => 1, 'action' => 2, 'params' => 3));
return $router;
開發者ID:CloudOJ,項目名稱:PhalconBootstrap,代碼行數:6,代碼來源:routes.php


注:本文中的Phalcon\Mvc\Router::add方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。