/** * 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); }
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; }
protected function initRouter() { $this->getDI()->set('router', function () { $router = new Router(); $router->setDefaultModule('hrm'); return $router; }); }
/** * 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); }
/** * 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); }
<?php use Phalcon\Mvc\Router; /* ================================================== * ลงทะเบียน "เส้นทางเว็บแอพพลิเคชั่น" (Router) * Registering a router * ================================================== */ $config = $this->config; // Read the configuration $manager->set('router', function () use($config) { $router = new Router(); $router->setDefaultModule($config->router->moduleDefault); $router->setDefaultController($config->router->controllerDefault); $router->setDefaultAction($config->router->actionDefault); $router->removeExtraSlashes(TRUE); $addModule = explode(',', $config->module->moduleLists); foreach ($addModule as $module) { $pathModule = APPLICATION_PATH . '/modules/' . $module . '/Router.php'; $nameModule = ucfirst($module) . 'Router'; if (file_exists($pathModule)) { include_once $pathModule; $router->mount(new $nameModule($config)); } } return $router; });
use Phalcon\Mvc\Url as UrlResolver; use Phalcon\Di\FactoryDefault; use Phalcon\Session\Adapter\Files as SessionAdapter; use Phalcon\Mvc\Model\Metadata\Memory as MetaDataAdapter; use Phalcon\Mvc\View; use Phalcon\Mvc\View\Engine\Volt as VoltEngine; /** * The FactoryDefault Dependency Injector automatically registers the right services to provide a full stack framework */ $di = new FactoryDefault(); /** * Registering a router */ $di->setShared('router', function () { $router = new Router(); $router->setDefaultModule('core'); $router->setDefaultNamespace('Phlame\\Core\\Controllers'); return $router; }); /** * The URL component is used to generate all kinds of URLs in the application */ $di->setShared('url', function () use($config) { $url = new UrlResolver(); $url->setBaseUri($config->application->baseUri); return $url; }); /** * Setting up the view component */ //$di->setShared('view', function () use ($config) {
<?php use Phalcon\Mvc\Router, Phalcon\Mvc\Router\Group as RouterGroup; $router = new Router(false); $router->setDefaultModule(SITENAME); $router->removeExtraSlashes(true); $router->setUriSource(Router::URI_SOURCE_SERVER_REQUEST_URI); $router->add('/', array('controller' => 'Index', 'action' => 'index'))->setName('homepage'); $router->add('/testMenu/{store_id:[a-z0-9\\-_A-Z]+}', array('controller' => 'Index', 'action' => 'testMenu'))->setName('homepage-test'); $router->add('/menu/ajax/{store_id:[a-z0-9\\-_A-Z]+}', array('controller' => 'Index', 'action' => 'menuAjax'))->setName('homepage-ajax'); /* Orders */ $router->add('/order/{order_id:[a-z0-9\\-_A-Z]+}', array('controller' => 'Order', 'action' => 'index'))->setName('order'); $router->add('/order/{order_id:[a-z0-9\\-_A-Z]+}/{drink_id:[a-z0-9\\-_A-Z]+}/{coldheat_id:[a-z0-9\\-_A-Z]+}', array('controller' => 'Order', 'action' => 'orderDrink'))->setName('order-drink'); $router->add('/order/{order_id:[a-z0-9\\-_A-Z]+}/overview', array('controller' => 'Order', 'action' => 'orderOverview'))->setName('order'); $router->add('/order/add-drink', array('controller' => 'Order', 'action' => 'addDrink'))->setName('order-add-drink'); /* resouces */ $router->add('/resource/stores', array('controller' => 'Resource', 'action' => 'stores'))->setName('resouce-stores'); $router->add('/resource/oStore/{order_id:[a-z0-9\\-_A-Z]+}', array('controller' => 'Resource', 'action' => 'orderStore'))->setName('resouce-order-store'); $router->add('/resource/oDrink/{drink_id:[a-z0-9\\-_A-Z]+}/{coldheat_id:[a-z0-9\\-_A-Z]+}', array('controller' => 'Resource', 'action' => 'orderDrink'))->setName('resouce-drink-detail'); $router->add('/resource/oDrinkList/{order_id:[a-z0-9\\-_A-Z]+}', array('controller' => 'Resource', 'action' => 'orderDrinkList'))->setName('resouce-drink-detail'); $router->add('/order/hook/{store_id:[a-z0-9\\-_A-Z]+}', array('controller' => 'Order', 'action' => 'hookOrder'))->setName('order-hook'); $router->notFound(array('controller' => 'Index', 'action' => 'notFound'));
public function diRouter() { $di = $this->getDI(); $cachePrefix = $this->getAppName(); $cacheFile = $this->getConfigPath() . "/_cache.{$cachePrefix}.router.php"; if ($router = $this->readCache($cacheFile, true)) { return $router; } $moduleManager = $di->getModuleManager(); $config = new Config(); $moduleName = ''; if ($moduleManager && ($modulesArray = $moduleManager->getModules())) { foreach ($modulesArray as $moduleName => $module) { //NOTICE: EvaEngine Load front-end router at last $config->merge(new Config($moduleManager->getModuleRoutesFrontend($moduleName))); $config->merge(new Config($moduleManager->getModuleRoutesBackend($moduleName))); } } //Disable default router $router = new Router(false); //Last extra slash $router->removeExtraSlashes(true); //Set last module as default module $router->setDefaultModule($moduleName); //NOTICE: Set a strange controller here to make router not match default index/index $router->setDefaultController('EvaEngineDefaultController'); $config = $config->toArray(); foreach ($config as $url => $route) { if (count($route) !== count($route, COUNT_RECURSIVE)) { if (isset($route['pattern']) && isset($route['paths'])) { $method = isset($route['httpMethods']) ? $route['httpMethods'] : null; $router->add($route['pattern'], $route['paths'], $method); } else { throw new Exception\RuntimeException(sprintf('No route pattern and paths found by route %s', $url)); } } else { $router->add($url, $route); } } if (!$di->getConfig()->debug) { $this->writeCache($cacheFile, $router, true); } else { //Dump merged routers for debug $this->writeCache($this->getConfigPath() . "/_debug.{$cachePrefix}.router.php", $router, true); } return $router; }
/** * * @param type $options */ protected function initRouter($options = []) { $this->_di->setShared('router', function () { $router = new Router(); $router->setDefaultModule('intranet'); $router->setDefaultNamespace('Intranet\\Controllers'); $router->removeExtraSlashes(true); return $router; }); }
/** * */ public function setDefaultModule($moduleName) { parent::setDefaultModule($moduleName); $this->addStdModule($moduleName); $this->defaultModule = $moduleName; }
<?php use Phalcon\Mvc\Router; $router = new Router(); //Remove trailing slashes automatically $router->removeExtraSlashes(true); $router->setDefaultModule("backend"); $router->setDefaultNamespace("DigitalKrikits\\Backend\\Controllers"); return $router;
<?php use Phalcon\Mvc\Router; $di->set('router', function () use($modules, $defaultModule) { $router = new Router(false); /** * Remove Extra Slashes * http://docs.phalconphp.com/en/latest/reference/routing.html#dealing-with-extra-trailing-slashes */ $router->removeExtraSlashes(true); /** * Setting Default Paths * http://docs.phalconphp.com/en/latest/reference/routing.html#setting-default-paths */ if (!empty($defaultModule)) { $router->setDefaultModule($defaultModule); } /** * Set Default Route * http://docs.phalconphp.com/en/latest/reference/routing.html#setting-the-default-route */ $router->add('/', array('controller' => 'index', 'action' => 'index')); /** * Set Not Found Page * http://docs.phalconphp.com/en/latest/reference/routing.html#not-found-paths * See [app.config.dispatcher.php] */ // $router->notFound(array( // 'controller' => 'error', // 'action' => 'e404' // ));
/** * Initializes the router * * @param array $options */ public function initRouter($options = []) { $config = $this->di['config']; $loader = $this->di['loader']; $this->di->setShared('router', function () use($config, $loader) { $router = new PhRouter(false); $router->setDefaultModule('common'); foreach ($config['app_routes'] as $route => $params) { $router->add($route, (array) $params)->setHostName($config->app_baseUri); } if (SUBDOMAIN == 'm') { $router->setDefaultModule('mobile'); $mobileRoutes = ['/:controller' => ['module' => 'mobile', 'controller' => 1], '/:controller/:action/:params' => ['module' => 'mobile', 'controller' => 1, 'action' => 2, 'params' => 3], '/' => ['module' => 'mobile', 'controller' => 'index', 'action' => 'index']]; foreach ($mobileRoutes as $route => $params) { $router->add($route, (array) $params)->setHostName('m.' . $config->app_baseUri); } } $router->removeExtraSlashes(true); return $router; }); }
* Regitrar Config */ $di->set("config", function () use($config) { return $config; }); /** * Registering a router */ $di->setShared('router', function () use($config) { $router = new Router(); //var_dump($config->application->modules);die(); /** * Include routes */ require __DIR__ . '/../config/routes.php'; $router->setDefaultModule('cliente'); $router->setDefaultNamespace('Ticobox\\Cliente\\Controllers'); return $router; }); /** * The URL component is used to generate all kinds of URLs in the application */ $di->setShared('url', function () use($config) { $url = new UrlResolver(); $url->setBaseUri($config->application->baseUri); return $url; }); /** * Setting up the view component */ $di->setShared('view', function () use($config) {
use Phalcon\Mvc\Router; use Phalcon\Mvc\Url as UrlResolver; use Phalcon\DI\FactoryDefault; use Phalcon\Session\Adapter\Files as SessionAdapter; use Phalcon\Loader; /** * The FactoryDefault Dependency Injector automatically register the right services providing a full stack framework */ $di = new FactoryDefault(); /** * Registering a router */ $di['router'] = function () use($di) { $router = new Router(); if (!isMobile() || !empty($_GET['v']) && $_GET['v'] == 'p') { $router->setDefaultModule("webpc"); $di['isMobile'] = function () { return 0; }; } else { $router->setDefaultModule("mobile"); $di['isMobile'] = function () { return 1; }; } $router->add("/login", array('controller' => 'index', 'action' => 'login')); $router->add("/register", array('controller' => 'index', 'action' => 'register')); $router->add("/registersuccess", array('controller' => 'index', 'action' => 'registersuccess')); return $router; }; /**
*/ use Phalcon\Mvc\Router; use Phalcon\Mvc\Url as UrlResolver; use Phalcon\DI\FactoryDefault; use Phalcon\Session\Adapter\Files as SessionAdapter; use Phalcon\Loader; /** * The FactoryDefault Dependency Injector automatically register the right services providing a full stack framework */ $di = new FactoryDefault(); /** * Registering a router */ $di['router'] = function () use($di) { $router = new Router(); $router->setDefaultModule('mall'); return $router; }; /** * The URL component is used to generate all kind of urls in the application */ $di['url'] = function () { $url = new UrlResolver(); $url->setBaseUri('/'); return $url; }; /** * Start the session the first time some component request the session service */ $di['session'] = function () { $session = new SessionAdapter();
<?php /** * routers.php Class * @author Phan Nguyen. * @email: phannguyen2020@gmail.com * @category: framework */ use Phalcon\Mvc\Router; $router = new Router(); $router->setDefaultModule('site'); //$router->setDefaultNamespace('Modules\Site\Controllers'); $router->add('/admin', array('module' => 'admin')); $router->add('/admin/:controller/:action/:params', array('module' => 'admin', 'controller' => 1, 'action' => 2, 'params' => 3)); $router->add('/admin/:controller', array('module' => 'admin', 'controller' => 1)); $router->add('/admin/logout', array('module' => 'admin', 'controller' => 'index', 'action' => 'logout')); //$router->setUriSource(\Phalcon\Mvc\Router::URI_SOURCE_SERVER_REQUEST_URI); $router->removeExtraSlashes(true); return $router;
use Phalcon\Mvc\Url as UrlResolver; use Phalcon\Di\FactoryDefault; use Phalcon\Session\Adapter\Files as SessionAdapter; use Phalcon\Mvc\Model\Metadata\Memory as MetaDataAdapter; use Phalcon\Mvc\View; use Phalcon\Mvc\View\Engine\Volt as VoltEngine; /** * The FactoryDefault Dependency Injector automatically registers the right services to provide a full stack framework */ $di = new FactoryDefault(); /** * Registering a router */ $di->setShared('router', function () { $router = new Router(); $router->setDefaultModule('anonymous'); $router->setDefaultNamespace('hoctap\\Anonymous\\Controllers'); return $router; }); /** * The URL component is used to generate all kinds of URLs in the application */ $di->setShared('url', function () use($config) { $url = new UrlResolver(); $url->setBaseUri($config->application->baseUri); return $url; }); /** * Setting up the view component */ $di->setShared('view', function () use($config) {
/** * initialize the router component * * @return Router */ public function init() { $router = new PhRouter(); $router->setDefaultModule('frontend'); $routes = $this->provider(); foreach ($routes as $settings) { $route = $this->addRoute($router, $settings['route'], $settings['params']); $this->setAlias($route, $this->getAlias($settings)); $this->setHttpMethods($route, $this->getHttpMethods($settings)); } return $router; }
<?php use Phalcon\Mvc\Router; $router = new Router(); //$router = new Router(false); $router->removeExtraSlashes(true); // 移除URL多余的斜杠 //$router->setUriSource(Router::URI_SOURCE_GET_URL); $router->setDefaultController('index'); $router->setDefaultAction('index'); $router->setDefaultModule('appApi'); $router->setDefaultNamespace('Apps\\AppApi\\Controllers'); // APP API $router->add('/appApi', ['module' => 'appApi', 'namespace' => 'Apps\\AppApi\\Controllers\\', 'controller' => 'index', 'action' => 'index']); $router->add('/appApi' . '/:action', ['module' => 'appApi', 'namespace' => 'Apps\\AppApi\\Controllers\\', 'controller' => 'index', 'action' => 1]); $defaultController = 'index'; $defaultAction = 'index'; $urlBase = ['/pay' => ['module' => 'pay', 'namespace' => 'Apps\\Pay\\Controllers\\']]; foreach ($urlBase as $k => $v) { $module = $v['module']; $namespace = $v['namespace']; $router->add($k . '/:params', ['module' => $module, 'namespace' => $namespace, 'controller' => $defaultController, 'action' => $defaultAction, 'params' => 1]); $router->add($k . '/:controller/:params', ['module' => $module, 'namespace' => $namespace, 'controller' => 1, 'action' => $defaultAction, 'params' => 2]); $router->add($k . '/:controller/:action/:params', ['module' => $module, 'namespace' => $namespace, 'controller' => 1, 'action' => 2, 'params' => 3]); } return $router;
* Services are globally registered in this file */ use Phalcon\Mvc\Router; use Phalcon\Mvc\Url as UrlResolver; use Phalcon\DI\FactoryDefault; use Phalcon\Session\Adapter\Files as SessionAdapter; /** * The FactoryDefault Dependency Injector automatically register the right services providing a full stack framework */ $di = new FactoryDefault(); /** * Registering a router */ $di['router'] = function () { $router = new Router(); $router->setDefaultModule("frontend"); $router->setDefaultNamespace("@@namespace@@\\Frontend\\Controllers"); return $router; }; /** * The URL component is used to generate all kind of urls in the application */ $di['url'] = function () { $url = new UrlResolver(); $url->setBaseUri('/@@name@@/'); return $url; }; /** * Start the session the first time some component request the session service */ $di['session'] = function () {
/** * The FactoryDefault Dependency Injector automatically register the right services providing a full stack framework */ $di = new FactoryDefault(); /** * Registering a router */ $di['router'] = function () use($di) { $router = new Router(); $router->handle(); $gateWay = new \Apiserver\Utils\GateWay($di); if (!$gateWay->check($router->getControllerName(), $router->getActionName())) { echo json_encode($gateWay->errMsg()); exit; } $router->setDefaultModule('api_' . $gateWay->ver); return $router; }; /** * The URL component is used to generate all kind of urls in the application */ $di['url'] = function () { $url = new UrlResolver(); $url->setBaseUri('/'); return $url; }; $di['view'] = function () { $view = new Phalcon\Mvc\View(); return $view; }; /**
<?php use Phalcon\Mvc\Router; $router = new Router(); //$router = new Router(false); $router->removeExtraSlashes(true); // 移除URL多余的斜杠 //$router->setUriSource(Router::URI_SOURCE_GET_URL); $router->setDefaultController('index'); $router->setDefaultAction('index'); $router->setDefaultModule('frontend'); $router->setDefaultNamespace('Apps\\Frontend\\Controllers'); // APP API $router->add('/appApi', ['module' => 'appApi', 'namespace' => 'Apps\\AppApi\\Controllers\\', 'controller' => 'index', 'action' => 'index']); $router->add('/appApi' . '/:action', ['module' => 'appApi', 'namespace' => 'Apps\\AppApi\\Controllers\\', 'controller' => 'index', 'action' => 1]); $defaultController = 'index'; $defaultAction = 'index'; $urlBase = ['/backend' => ['module' => 'backend', 'namespace' => 'Apps\\Backend\\Controllers\\'], '/manage' => ['module' => 'manage', 'namespace' => 'Apps\\Manage\\Controllers\\'], '/frontend' => ['module' => 'frontend', 'namespace' => 'Apps\\Frontend\\Controllers\\'], '/pay' => ['module' => 'pay', 'namespace' => 'Apps\\Pay\\Controllers\\']]; foreach ($urlBase as $k => $v) { $module = $v['module']; $namespace = $v['namespace']; $router->add($k . '/:params', ['module' => $module, 'namespace' => $namespace, 'controller' => $defaultController, 'action' => $defaultAction, 'params' => 1]); $router->add($k . '/:controller/:params', ['module' => $module, 'namespace' => $namespace, 'controller' => 1, 'action' => $defaultAction, 'params' => 2]); $router->add($k . '/:controller/:action/:params', ['module' => $module, 'namespace' => $namespace, 'controller' => 1, 'action' => 2, 'params' => 3]); } return $router;
public function setDefaultModule($moduleName) { return parent::setDefaultModule($moduleName); }