本文整理汇总了PHP中Router::route方法的典型用法代码示例。如果您正苦于以下问题:PHP Router::route方法的具体用法?PHP Router::route怎么用?PHP Router::route使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Router
的用法示例。
在下文中一共展示了Router::route方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
public static function init(){
ob_start();
self::$request = new Request();
Router::init();
Router::route();
}
示例2: init
private function init()
{
//get user requested route
if (isset($_GET['node'])) {
//define route without parameters (helps with showing base URI request)
$route = $_GET['node'];
self::$route = $route;
//break requested route into chunks in array
$route_chunks = explode("/", $route);
//define controller
$controller = $route_chunks[0];
self::$controller = $controller;
//define controller directory
$controller_dir = CONTROLLER_DIR . $controller;
self::$controller_dir = $controller_dir;
//define format
if (!empty($route_chunks[1])) {
$format = $route_chunks[1];
self::$format = $format;
}
//define parameters - get full url etc and extract all strings after &..
global $settings;
$request_uri = $settings['request_uri'];
//break requested route into chunks in array
$route_params = explode("&", $request_uri);
//remove first value from array & return $route_params as just parameters
$params_shift = array_shift($route_params);
//update $params array
foreach ($route_params as $val) {
$param_chunks = explode("=", $val);
$params[$param_chunks[0]] = $param_chunks[1];
}
self::$params = $params;
}
}
示例3: route
/**
* Change the router state according to the error Code
* @param string $errorRouteId
* @param \Exception $error
* @throws Exception
* @throws \Exception
*/
public function route($errorCode, $error)
{
// Router knows a route for this error code
if (isset($this->routeId[$errorCode])) {
$errorRouteId = $this->routeId[$errorCode];
} else {
$errorRouteId = null;
}
if ($this->_router->ruleExists($errorRouteId)) {
// There is a specific route for this error code
$errorRoute = $errorRouteId;
} elseif ($this->_router->ruleExists(self::ROUTE_ALL_ERROR)) {
// There is a default route for all errors
$errorRoute = self::ROUTE_ALL_ERROR;
} else {
// No route for error, do nothing
$errorRoute = null;
}
if ($errorRoute !== null) {
try {
// Prepare redirecting in the router
$this->_router->route($this->_router->getPrefix() . '/' . $errorRoute);
$this->_router->setVariable('err', $error);
} catch (\Exception $e) {
// The router is unable to route the error
throw new Exception('Unable to handle error ' . $e, 0, $e);
}
} else {
// There is no error route for this error code, just transfert the exception
throw $error;
}
}
示例4: testRouteWithInvalidHttpMethod
/**
* @covers Zepto\Router::route()
* @expectedException InvalidArgumentException
*/
public function testRouteWithInvalidHttpMethod()
{
$this->router->route(new \Zepto\Route('/test', function () {
return 'New test route';
}), 'NO_SUCH_METHOD');
$routes = $this->router->routes();
$this->assertArrayNotHasKey('NO_SUCH_METHOD', $routes);
}
示例5: dispatch
function dispatch()
{
$router = new Router(Request::instance());
$array = $router->route();
extract($array);
// instantiates the controller and runs the action (method) we got from above
$controller = new $controller();
$controller->{$action}();
}
示例6: __construct
/**
* Protected constructor to prevent creating a new instance of the
* *Services* via the `new` operator from outside of this class.
*/
protected function __construct()
{
parent::__construct();
$this->config = new Config();
$this->input = new Input($this->config->get('config'));
$this->output = new Output($this->config->get('mimes'));
$router = new Router($this->config->get('routes'));
$this->route = $router->route($this->input->uri());
}
示例7: testManyActionParams
public function testManyActionParams()
{
$uri = '/test/test/param1/param2/param3/param4/param5/param6';
ob_start();
$router = new Router($uri, $this->path);
$router->route();
$response = ob_get_clean();
$this->assertEquals('test', $response);
}
示例8: route
/**
* This method is only here as a legacy decorator, use url::to.
*
* @return \League\URL\URLInterface
*
* @deprecated
*/
public static function route($data)
{
$arguments = array_slice(func_get_args(), 1);
if (!$arguments) {
$arguments = array();
}
$route = \Router::route($data);
array_unshift($arguments, $route);
return static::getFacadeRoot()->resolve($arguments);
}
示例9: render
public function render()
{
error_reporting(E_ALL);
ini_set('display_errors', 1);
Application::loadLibrary('olmi/request');
Application::loadLibrary('core/router');
$url = ltrim($_SERVER['REQUEST_URI'], '/');
$user_session = Application::getUserSession();
$user_logged = $user_session->getUserAccount();
Router::setDefaultModuleName($user_logged ? 'profile' : 'login');
Router::route($url);
$page = Application::getPage();
$page = Application::getPage();
$page->setTitle('OCS');
$page->addMeta(array('name' => 'viewport', 'content' => 'width=device-width, initial-scale=1'));
$page->addMeta(array('charset' => 'utf-8'));
$page->addStylesheet(coreResourceLibrary::getStaticPath('/bootstrap/css/bootstrap.min.css'));
$page->addStylesheet(coreResourceLibrary::getStaticPath('/bootstrap/css/bootstrap-theme.min.css'));
$page->addStylesheet(coreResourceLibrary::getStaticPath('jquery-ui/jquery-ui-bootstrap.css'));
$page->addStylesheet(coreResourceLibrary::getStaticPath('/css/admin.css'));
$page->addScript(coreResourceLibrary::getStaticPath('/js/jquery-1.11.3.min.js'));
$page->addScript(coreResourceLibrary::getStaticPath('/jquery-ui/jquery-ui.min.js'));
$page->addScript(coreResourceLibrary::getStaticPath('/bootstrap/js/bootstrap.min.js'));
$page->addScript(coreResourceLibrary::getStaticPath('/js/application.js'));
$page->addLiteral('
<script type="text/javascript">
jQuery(document).ready(function(){
App.init();
});
</script>
');
$smarty = Application::getSmarty();
$module_name = Router::getModuleName();
$module_params = Router::getModuleParams();
if ($module_name) {
$module = Application::getResourceInstance('module', $module_name);
if (coreAccessControlLibrary::accessAllowed($user_logged, $module)) {
$content = call_user_func(array($module, 'run'), $module_params);
} else {
Application::stackError(Application::gettext('You have no permission to login'));
$user_session->logout();
Redirector::redirect(Application::getSeoUrl('/login?back=' . Router::getSourceUrl()));
}
} else {
$content = Application::runModule('page404');
}
$smarty->assign('content', $content);
$html_head = $page->getHtmlHead();
$smarty->assign('html_head', $html_head);
/*$smarty->assign('header', Application::getBlock('header'));
$smarty->assign('footer', Application::getBlock('footer'));*/
$template_path = coreResourceLibrary::getTemplatePath('index');
$smarty->display($template_path);
}
示例10: handleCGI
/**
* Dispatcher for CGI mode.
*/
public static function handleCGI()
{
require APP_PATH . 'controller/Base.php';
Router::responseFrontEndFiles('static');
$oController = Router::route($_SERVER['REQUEST_URI'], APP_PATH);
$oController->before();
$aData = $oController->handle();
$sOutputType = $oController->getOutputType();
Output::handle($aData, $sOutputType);
$oController->after();
}
示例11: run
public function run($config)
{
self::register('db', $config['db'], false);
self::$_loader = new Autoloader();
self::$_loader->register();
$session = new Session();
$session->start();
$url = substr($_SERVER['REQUEST_URI'], 1);
if ($url != '') {
$router = new Router(self::$_loader, 'App');
$router->route();
}
}
示例12: routeRequest
/**
* The request router looks at the URI path, tries to load it from /assets,
* then tries to route the request through the Router if it's a model.
* If it's not a model, the PageEngine tries to render the template file.
*/
function routeRequest()
{
$path = getPath();
if (!$path) {
return PageEngine::renderPage('index');
}
if (File::find("assets/{$path}")) {
File::render("assets/{$path}");
}
try {
$router = new Router();
return $router->route($path);
} catch (ModelExistenceException $e) {
return PageEngine::renderPage($path);
}
}
示例13: handle
public function handle()
{
$request = $this->configuration->getRequest();
$response = $this->configuration->getResponse();
$request = Router::route($request);
$mainController = $this->configuration->getController();
if (is_null($mainController)) {
$response->set('Not found');
$response->setStatus(404, 'Not Found');
return $response->render();
}
$returnValue = $mainController->handle();
if (!is_null($returnValue)) {
$response->add($returnValue);
}
return $response->render();
}
示例14: route
/**
* return the first matching routes with matching additionnal param if any,
* return false if no match
*
* @return mixed the first matching Route or false if no match
*/
function route()
{
$routes = $this->_routes->getRoutes();
foreach ($routes as $route) {
$options = $route->match($this->_url);
if (is_array($options)) {
if ($route->isKnownLocation()) {
return $route;
} else {
$simplified_url = $route->simplify($this->_url);
$location = $route->getLocation();
$router = new Router($simplified_url, $location);
return $router->route();
}
}
}
return false;
}
示例15: route
/**
* route Handles incoming requests.
*
* @access public
* @return void
*/
public function route()
{
global $logger;
try {
// TODO : Refactor Code :
// $url = URLParser::parse();
// $route = RouteMapper::getRoute($url['route']);
// $router = new Router();
// $router->route($route);
$urlInterpreter = new UrlInterpreter();
$command = $urlInterpreter->getCommand();
$router = new Router($command);
$logger->debug('Routing to : ' . $command->getControllerName());
$router->route();
} catch (Exception $e) {
throw new RouteNotFoundException();
}
}