本文整理汇总了PHP中Router::getRoute方法的典型用法代码示例。如果您正苦于以下问题:PHP Router::getRoute方法的具体用法?PHP Router::getRoute怎么用?PHP Router::getRoute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Router
的用法示例。
在下文中一共展示了Router::getRoute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getController
public function getController()
{
$router = new Router();
$xml = new \DOMDocument();
$xml->load(__DIR__ . '/../../App/' . $this->name . '/Config/route.xml');
$routes = $xml->getElementByTagName("route");
foreach ($routes as $route) {
$vars = [];
if ($route->hasAttribute('vars')) {
$vars = explode(',', $route->getAttribute('vars'));
}
$router->addRoute(new Route($route->getAttribute('url'), $route->getAttribute('module'), $route->getAttribute('action'), $vars));
}
try {
$matched_route = $router->getRoute($this->httpRequest->requestURI());
} catch (\RuntimeException $exception) {
if ($exception->getCode() == Router::NO_ROUTE) {
$this->httpResponse->redirect404();
}
}
// Add variables in tab: $_GET
$_GET = array_merge($_GET, $matched_route->module(), $matched_route->action());
// Instancie the controller
$controller_class = 'App\\' . $this->name . '\\Modules\\' . $matched_route->module() . '\\' . $matched_route->module() . 'Controllers';
return new $controller_class($this, $matched_route->module(), $matched_route->action());
}
示例2: generateResponse
public function generateResponse($route = null, $params = array(), $internal = false)
{
$router = new Router();
$request = Request::getInstance();
$request->setInternal($internal);
if ($route) {
$route = $router->getRoute($route);
} else {
$route = $router->getDefaultRoute();
}
$controller = $route->getController();
$action = $route->getAction();
$controller = new $controller();
$r = new ReflectionMethod($controller, $action);
$paramsOfFunction = $r->getParameters();
$paramsToPass = array();
$indexParams = 0;
foreach ($paramsOfFunction as $param) {
if ($param->getClass() != NULL && $param->getClass()->getName() == 'Request') {
$paramsToPass[] = $request;
} else {
if (isset($params[$indexParams])) {
$paramsToPass[] = $params[$indexParams++];
} else {
$paramsToPass[] = null;
}
}
}
if (!empty($paramsToPass)) {
return call_user_func_array(array($controller, $action), $paramsToPass);
}
return $controller->{$action}();
}
示例3: beforeAction
public function beforeAction()
{
// auto find model entry when id passed
if (isset($this->params['id'])) {
if (!$this->{$this->name}->fromId($this->params['id'])) {
return false;
}
$this->data->set($this->name, $this->{$this->name});
}
// send invalid logins (invalid user group) back to loing page
if (!$this->UserLogin->loggedin() && empty($this->publicActions)) {
$this->redirect(Router::getRoute('adminLogin'));
}
// change language on users locale
if (isset($this->I18n) && $this->UserLogin->loggedin() && $this->User->hasField('locale')) {
$this->I18n->locale($this->UserLogin->User->locale);
}
// if mobile layout selected, use other action view files
if ($this->layout == 'mobile') {
// and increase number of returned model entries
if (!empty($this->{$this->name})) {
$this->{$this->name}->perPage = 50;
if (!in_array($this->action, array('edit', 'view'))) {
$this->{$this->name}->depth = 0;
}
}
$this->action .= '.mobile';
}
return parent::beforeAction();
}
示例4: getController
public function getController()
{
$Router = new Router();
$this->Router = $Router;
$xml = new \DOMDocument();
$xml->load(__DIR__ . '/../../App/' . $this->name . '/Config/routes.xml');
$routes = $xml->getElementsByTagName('route');
// On parcourt les routes du fichier XML.
foreach ($routes as $route) {
$vars = [];
// On regarde si des variables sont présentes dans l'URL.
if ($route->hasAttribute('vars')) {
$vars = explode(',', $route->getAttribute('vars'));
}
// On ajoute la route au routeur.
$Router->addRoute(new Route($route->getAttribute('url'), $route->getAttribute('module'), $route->getAttribute('action'), $vars));
}
try {
// On récupère la route correspondante à l'URL.
$matchedRoute = $Router->getRoute($this->httpRequest->requestURI());
} catch (\RuntimeException $e) {
if ($e->getCode() == Router::NO_ROUTE) {
// Si aucune route ne correspond, c'est que la page demandée n'existe pas.
$this->httpResponse->redirect404();
}
}
// On ajoute les variables de l'URL au tableau $_GET.
$_GET = array_merge($_GET, $matchedRoute->vars());
// On instancie le contrôleur.
$controllerClass = 'App\\' . $this->name . '\\Modules\\' . $matchedRoute->module() . '\\' . $matchedRoute->module() . 'Controller';
return new $controllerClass($this, $matchedRoute->module(), $matchedRoute->action());
}
示例5: ajaxSearch
public function ajaxSearch()
{
$search = $_GET['s'];
$groups = $this->group->getGroupInfoByName($search);
$sports = $this->acc->getSportsByName($search);
$users = $this->acc->getUsersByName($search);
echo json_encode(["groupe" => array_slice($groups, 0, 5), "urlgroupe" => $_GET['lang'] . "/" . Router::getRoute('groupe'), "sports" => array_slice($sports, 0, 5), "urlsport" => $_GET['lang'] . "/" . Router::getRoute('SportGroupe'), "users" => array_slice($users, 0, 5)]);
}
示例6: __construct
/**
*
*/
public function __construct()
{
$this->View = View::getInstance();
$this->Model = Router::getRoute()['Controller'];
$this->loadModel($this->Model);
$this->Request = Request::getInstance();
$this->Session = Session::getInstance();
Orm::getInstance();
}
示例7: delete
/**
* Delete single {@link UserGroup}
*
* @param integer $id
* @return boolean
*/
public function delete($id = null)
{
if ($this->UserGroup->delete()) {
$this->FlashMessage->set(__('Die Benutzergruppe <q>:1</q> wurder erfolgreich gelöscht.', $this->UserGroup->get('name')), FlashMessageType::SUCCESS);
} else {
$this->FlashMessage->set(__('Es ist ein Fehler beim Löschen der Benutzergruppe aufgetreten.'), FlashMessageType::ERROR);
}
return $this->redirect(Router::getRoute('adminScaffold', array('controller' => $this->name)));
}
示例8: delete
public function delete($id = null)
{
if (parent::delete($id)) {
$this->FlashMessage->set(__('Blogeintrag erfolgreich gelöscht.'), FlashMessageType::SUCCESS);
} else {
$this->FlashMessage->set(__('Fehler beim Löschen des Blogeintrags.'), FlashMessageType::ERROR);
}
$this->redirect(Router::getRoute('adminBlogPost'));
}
示例9: delete
public function delete($id = null)
{
if (parent::delete($id)) {
$this->FlashMessage->set(__('Zugriffsrecht erfolgreich gelöscht.'), FlashMessageType::SUCCESS);
} else {
$this->FlashMessage->set(__('Fehler beim Löschen des Zugriffsrecht.'), FlashMessageType::ERROR);
}
$this->redirect(Router::getRoute('adminScaffold', array('controller' => $this->name)));
}
示例10: delete
public function delete($id = null)
{
if (parent::delete($id)) {
$this->MediaFile->updateWhere(array('folder_id' => (int) $id), array('folder_id' => 'NULL'));
$this->FlashMessage->set(__('Die Kategorie wurde erfolgreich gelöscht. Dateien die in dieser Kategorie waren sind nun nicht mehr zugeordnet'));
} else {
$this->FlashMessage->set(__('Fehler beim Löschen der Kategorie'));
}
$this->redirect(Router::getRoute('adminMediaFiles'));
}
示例11: run
public function run(Query $config)
{
// Set the timezone for the user using the system one
Utils::defineTimeZone();
// Retrieve the route from the given parameters
$route = Router::getRoute($config);
if ($route !== false) {
$this->invoke($route);
}
}
示例12: parseRequest
public function parseRequest()
{
if (isset($_SERVER['REDIRECT_URL']) && !empty($_SERVER['REDIRECT_URL'])) {
$url = $_SERVER['REDIRECT_URL'];
} else {
$url = $_SERVER['REQUEST_URI'];
}
list($handler, $args) = Router::getRoute($url);
return array($handler, $args);
}
示例13: detailPageUri
/**
* Return uri-string to a single blog entry
*/
public function detailPageUri(array $params = array())
{
if (!$this->exists()) {
return false;
}
if ($this->isEmpty('uri')) {
return Router::getRoute('blogEntryId', array('id' => $this->id));
} else {
return Router::getRoute('blogEntryUri', array('uri' => $this->uri));
}
}
示例14: adminDetailPageUri
/**
* Uses the router and the name of the model to return a detail page
* uri that leads to the detail page of of a model entry
* @param array(string) $additionalParams
* @return string
*/
public function adminDetailPageUri($additionalParams = array())
{
if (!is_array($additionalParams)) {
$additionalParams = array('action' => $additionalParams);
}
$params = array_merge(array('action' => '', 'id' => $this->id, 'controller' => $this->name), $additionalParams);
$uri = Router::getRoute('admin' . String::ucFirst($this->name) . 'Id', $params);
if (empty($uri)) {
$uri = Router::getRoute('adminScaffoldId', $params);
}
return $uri;
}
示例15: create
public function create()
{
$this->data->set('pageTitle', __('Sprache erstellen'));
if ($this->AdminLanguageForm->ok()) {
$this->AdminLanguageForm->toModel($this->Language);
if (!$this->Language->save()) {
$this->AdminLanguageForm->errors = $this->Language->validationErrors;
} else {
$this->FlashMessage->set(__('Die neue Sprache wurde erfolgreich angelegt.'), FlashMessageType::HINT);
$this->redirect(Router::getRoute('adminLanguage'));
}
}
}