本文整理汇总了PHP中Phalcon\Mvc\Router::mount方法的典型用法代码示例。如果您正苦于以下问题:PHP Router::mount方法的具体用法?PHP Router::mount怎么用?PHP Router::mount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phalcon\Mvc\Router
的用法示例。
在下文中一共展示了Router::mount方法的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);
}
示例2: setUp
public function setUp($di = null)
{
parent::setUp();
/**
* @type \DiCustom $di
*/
$di = $this->di;
$oConfig = $di->getConfig();
$oLoader = $di->getLoader();
$oLoader->registerNamespaces(array('App\\Modules\\Api' => $oConfig->application->modulesDir . '/api'), true);
$oRouter = new Router(false);
$di->setShared('router', $oRouter);
$this->router = $di->getRouter();
$this->router->mount(new ApiRoutes());
$this->setExistingRoutes();
}
示例3: 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;
}
示例4: Group
$router->removeExtraSlashes(true);
/*
* 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 Group(['module' => 'frontend']);
$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']);
示例5: Router
<?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;
示例6: Router
<?php
/**
* User: marnixjanssen
* Date: 6/7/15
*/
use Phalcon\Mvc\Router;
use Devnation\App\Routes\UserRoutes;
use Devnation\App\Routes\AjaxRoutes;
$router = new Router(false);
$router->setDefaultNamespace("Devnation\\App\\Controllers\\Main");
$router->add("/", ["controller" => "Index", "action" => "index"])->setName("home");
$router->add("/info/{city:[a-z\\-]+}", ["controller" => "Index", "action" => "index"]);
$router->mount(new UserRoutes());
$router->mount(new AjaxRoutes());
//$router->add("/ajax/weather/city/{city}", ["namespace" => "Devnation\\App\\Controllers\\Ajax", "controller" => "Weather", "action" => "weatherForCity"]);
//$router->add("/ajax/location/getAddress", ["namespace" => "Devnation\\App\\Controllers\\Ajax", "controller" => "Location", "action" => "getAddress"]);
//$router->add("/ajax/user/getFavorites", ["namespace" => "Devnation\\App\\Controllers\\Ajax", "controller" => "User", "action" => "getFavoriteLocations"]);
//$router->add("/ajax/user/setFavorite", ["namespace" => "Devnation\\App\\Controllers\\Ajax", "controller" => "User", "action" => "setFavoriteLocation"]);
//$router->add("/ajax/user/hasFavorite/{city}", ["namespace" => "Devnation\\App\\Controllers\\Ajax", "controller" => "User", "action" => "hasFavorite"]);
//$router->add("/ajax/user/weatherForCurrentLocation", ["namespace" => "Devnation\\App\\Controllers\\Ajax", "controller" => "User", "action" => "weatherForCurrentLocation"]);
return $router;
示例7: Router
<?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: function
/**
* Setting up custom Request object
*/
$di->set('request', function () {
return new RestRequest();
});
/**
* Setting up custom Dispatcher
*/
$di->set('dispatcher', function () {
return new RestDispatcher();
});
/**
* Setting up router and mounting AppRouter
*/
$di->set('router', function () {
$router = new Router(false);
$router->removeExtraSlashes(true);
$router->notFound(array('controller' => 'error404'));
$router->mount(new AppRouter());
return $router;
});
/**
* Run the application
*/
$app = new Application($di);
$app->useImplicitView(false);
$app->handle()->send();
} catch (Exception $e) {
echo 'Uncaught Exception: ' . get_class($e) . $e->getMessage();
}
示例9: Router
<?php
use Phalcon\Mvc\Router;
use Libraries\RouteLoader\RouteLoader;
// Create the router
$router = new Router(false);
// Get all available routes located in the routes dir recursively
$routeLoader = new RouteLoader($config->application->routesDir);
// Mount all available routes
foreach ($routeLoader->findRoutes() as $route) {
$router->mount(new $route());
}
//Set 404 paths
$router->notFound(array('namespace' => 'Controllers\\BaseControllers', 'controller' => 'error', 'action' => 'send404'));
// Return the router
return $router;
示例10: function
//});
/**
* If the configuration specify the use of metadata adapter use it or use memory otherwise
*/
$di->setShared('modelsMetadata', function () {
return new MetaDataAdapter();
});
/**
* Register the session flash service with the Twitter Bootstrap classes
*/
$di->set('flash', function () {
$flash = new Flash(array('error' => 'alert alert-danger', 'success' => 'alert alert-success', 'notice' => 'alert alert-info', 'warning' => 'alert alert-warning'));
return $flash;
});
$di->set('flashSession', function () {
$flashSession = new FlashSession(array('error' => 'alert alert-danger', 'success' => 'alert alert-success', 'notice' => 'alert alert-info', 'warning' => 'alert alert-warning'));
return $flashSession;
});
/**
* Start the session the first time some component request the session service
*/
$di->setShared('session', function () {
$session = new SessionAdapter();
$session->start();
return $session;
});
$di->set('router', function () {
$router = new Router();
$router->mount(new GlobalRoutes());
return $router;
});
示例11: Router
<?php
use Phalcon\Mvc\Router;
$router = new Router();
$router->clear();
$router->removeExtraSlashes(true);
// Add default route
$router->add("/", array("controller" => "index", "action" => "index"));
// Add 404 route
$router->notFound(array("controller" => "index", "action" => "index"));
// Add route groups
$router->mount(new \Pangea\Routes\AccountRoutes());
$router->mount(new \Pangea\Routes\TownRoutes());
$router->mount(new \Pangea\Routes\RaceRoutes());
return $router;
示例12: Router
<?php
/**
* Created by PhpStorm.
* User: rcmonitor
* Date: 30.06.15
* Time: 19:10
*/
use App\Modules\Api\ApiRoutes;
use Phalcon\Di;
use Phalcon\Loader;
use Phalcon\Mvc\Router;
$di = Di::getDefault();
$oLogger = $di->getFileLogger();
$oLogger->debug('initializing route');
/**
* @type Loader
*/
$oLoader = $di->getLoader();
$arClasses = $oLoader->getClasses();
$oLogger->debug(print_r($arClasses, true));
$oRouter = new Router();
$oApiRoutes = new ApiRoutes();
$oRouter->mount($oApiRoutes);
$di->setShared('router', $oRouter);
示例13: Router
<?php
use Phalcon\Mvc\Router;
use NetAssist\Routes\GraphRoutes;
use NetAssist\Routes\NodesRoutes;
use NetAssist\Routes\AccountRoutes;
use NetAssist\Routes\LinksRoutes;
$router = new Router(false);
$router->add("/", ['controller' => 'index', 'action' => 'index']);
$router->mount(new GraphRoutes());
$router->mount(new NodesRoutes());
$router->mount(new AccountRoutes());
$router->mount(new LinksRoutes());
$router->notFound(array("controller" => "index", "action" => "route404"));
$router->removeExtraSlashes(true);
return $router;
示例14: mount
public function mount($group)
{
if (method_exists($group, 'getTranslatedRoutes')) {
$this->translatedRoutes = array_merge_recursive($this->translatedRoutes, $group->getTranslatedRoutes());
}
return parent::mount($group);
}
示例15: function
<?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;
});