当前位置: 首页>>代码示例>>PHP>>正文


PHP Router::parse方法代码示例

本文整理汇总了PHP中Cake\Routing\Router::parse方法的典型用法代码示例。如果您正苦于以下问题:PHP Router::parse方法的具体用法?PHP Router::parse怎么用?PHP Router::parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cake\Routing\Router的用法示例。


在下文中一共展示了Router::parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 /**
  * construct method
  */
 public function __construct($request = null, $response = null)
 {
     $request->addParams(Router::parse('/auth_test'));
     $request->here = '/auth_test';
     $request->webroot = '/';
     Router::setRequestInfo($request);
     parent::__construct($request, $response);
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:11,代码来源:AuthTestController.php

示例2: add

 /**
  * Adds a comment in DB and redirects
  *
  * @return void
  */
 public function add()
 {
     $comment = $this->Comments->newEntity();
     // the body field should be empty as it's a honeypot for bots
     if ($this->request->is('post') && empty($this->request->data('body'))) {
         $data = $this->request->data;
         // Preparing data
         if (!empty($this->Auth->user('id'))) {
             $data['user_id'] = $this->Auth->user('id');
             $data['name'] = $this->Auth->user('username');
             $data['email'] = $this->Auth->user('email');
         } else {
             $data['user_id'] = null;
         }
         unset($data['body']);
         // Getting the route
         $route = Router::parse(str_replace(Router::url('/', true), '', $this->referer(true)));
         $data['fkid'] = $route['pass'][0];
         $data['model'] = $route['controller'];
         $comment = $this->Comments->patchEntity($comment, $data);
         if ($this->Comments->save($comment)) {
             if ($comment->allow_contact) {
                 $this->Flash->success(__d('elabs', 'Thank you for your comment. The author will contact you soon.'));
             } else {
                 $this->Flash->success(__d('elabs', 'Thank you for your comment.'));
             }
             $this->redirect($this->referer());
         } else {
             $this->Flash->error(__d('elabs', 'The comment could not be saved. Please try again.'));
         }
     }
     $this->redirect($this->referer());
 }
开发者ID:el-cms,项目名称:elabs,代码行数:38,代码来源:CommentsController.php

示例3: _generateOpauthCompleteUrl

 /**
  * Generates the opauth callback url
  *
  * @return string Full translated URL with base path.
  */
 protected function _generateOpauthCompleteUrl()
 {
     $url = Configure::read('Opauth.complete_url');
     if (!is_array($url)) {
         $url = Router::parse($url);
     }
     $url['?'] = ['social' => $this->request->query('code')];
     return Router::url($url, true);
 }
开发者ID:OrigamiStructures,项目名称:users,代码行数:14,代码来源:SocialTrait.php

示例4: beforeDispatch

 /**
  * Applies Routing and additionalParameters to the request to be dispatched.
  * If Routes have not been loaded they will be loaded, and config/routes.php will be run.
  *
  * @param \Cake\Event\Event $event containing the request, response and additional params
  * @return void
  */
 public function beforeDispatch(Event $event)
 {
     $request = $event->data['request'];
     Router::setRequestInfo($request);
     if (empty($request->params['controller'])) {
         $params = Router::parse($request->url);
         $request->addParams($params);
     }
 }
开发者ID:JesseDarellMoore,项目名称:CS499,代码行数:16,代码来源:RoutingFilter.php

示例5: filterRequest

 /**
  * Filters the BrowserKit request to the cake one.
  *
  * @param \Symfony\Component\BrowserKit\Request $request BrowserKit request.
  * @return \Cake\Network\Request Cake request.
  */
 protected function filterRequest(\Symfony\Component\BrowserKit\Request $request)
 {
     $url = preg_replace('/^https?:\\/\\/[a-z0-9\\-\\.]+/', '', $request->getUri());
     $_ENV = $environment = ['REQUEST_METHOD' => $request->getMethod()] + $request->getServer();
     $props = ['url' => $url, 'post' => (array) $request->getParameters(), 'files' => (array) $request->getFiles(), 'cookies' => (array) $request->getCookies(), 'session' => $this->getSession(), 'environment' => $environment];
     $this->cake['request'] = new Request($props);
     // set params
     Router::setRequestInfo($this->cake['request']);
     $this->cake['request']->params = Router::parse($url);
     return $this->cake['request'];
 }
开发者ID:cakephp,项目名称:codeception,代码行数:17,代码来源:Connector.php

示例6: index

 public function index()
 {
     if ($this->request->is('ajax')) {
         if ($this->request->is('post')) {
             $request = $this->request->data('request');
             $requestParams = Router::parse($request);
             $this->AdminBar->createAdminBar($requestParams);
             $this->layout = 'AdminBar.ajax';
         }
     }
 }
开发者ID:cakemanager,项目名称:cakeadmin-adminbar,代码行数:11,代码来源:AdminBarController.php

示例7: __invoke

 /**
  * @param ServerRequestInterface $request  The request.
  * @param ResponseInterface      $response The response.
  * @param callable               $next     The next middleware to call
  * @return RedirectResponse
  */
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next)
 {
     try {
         $params = (array) $request->getAttribute('params', []);
         if (empty($params['controller'])) {
             $path = $request->getUri()->getPath();
             $request = $request->withAttribute('params', Router::parse($path, $request->getMethod()));
         }
     } catch (RedirectException $e) {
         return new RedirectResponse($e->getMessage(), $e->getCode(), $response->getHeaders());
     }
     return $next($request, $response);
 }
开发者ID:markstory,项目名称:cakephp-spekkoek,代码行数:19,代码来源:RoutingMiddleware.php

示例8: check

 /**
  * Check if the user can access to the given URL.
  *
  * @param array $params The params to check.
  *
  * @return bool
  */
 public function check(array $params = [])
 {
     if (!$this->request->session()->read('Auth.User')) {
         return false;
     }
     $params += ['_base' => false];
     $url = Router::url($params);
     $params = Router::parse($url);
     $user = [$this->Authorize->config('userModel') => $this->request->session()->read('Auth.User')];
     $request = new Request();
     $request->addParams($params);
     $action = $this->Authorize->action($request);
     return $this->Acl->check($user, $action);
 }
开发者ID:Xety,项目名称:Xeta,代码行数:21,代码来源:AclHelper.php

示例9: link

 /**
  * This method provides conditional output of the desired link only if the current user has access to the controller action referenced by the
  * link.
  * @return Returns the constructed link if the current user has access to the controller action referenced by the link or false, if not.
  * @see \Cake\View\Helper\HtmlHelper::link() for additional information on the parameters.
  */
 public function link($title, $url = null, array $options = [])
 {
     $parsedRoute = Router::parse(Router::url($url !== null ? $url : $title));
     $annAuthorization = AnnAuthorization::getInstance();
     $userId = $this->request->session()->read('Auth.User.id');
     $controller = $parsedRoute['controller'];
     $action = $parsedRoute['action'];
     $pass = $parsedRoute['pass'];
     $requestAuthorized = $annAuthorization->authorizeRequest($userId, $controller, $action, $pass, $this->request);
     if ($requestAuthorized) {
         return $this->Html->link($title, $url, $options);
     }
     return false;
 }
开发者ID:michaelze,项目名称:cakephp-annauthorize,代码行数:20,代码来源:AnnAuthorizeHelper.php

示例10: beforeDispatch

 /**
  * Applies Routing and additionalParameters to the request to be dispatched.
  * If Routes have not been loaded they will be loaded, and config/routes.php will be run.
  *
  * @param \Cake\Event\Event $event containing the request, response and additional params
  * @return void|Cake\Network\Response A response will be returned when a redirect route is encountered.
  */
 public function beforeDispatch(Event $event)
 {
     $request = $event->data['request'];
     Router::setRequestInfo($request);
     try {
         if (empty($request->params['controller'])) {
             $params = Router::parse($request->url);
             $request->addParams($params);
         }
     } catch (RedirectException $e) {
         $response = $event->data['response'];
         $response->statusCode($e->getCode());
         $response->header('Location', $e->getMessage());
         return $response;
     }
 }
开发者ID:MillHidden,项目名称:BiellesMeusiennes,代码行数:23,代码来源:RoutingFilter.php

示例11: check

 /**
  * Checks a url for the route that will be applied.
  *
  * @param string $url The URL to parse
  * @return null|false
  */
 public function check($url)
 {
     try {
         $route = Router::parse($url);
         foreach (Router::routes() as $r) {
             if ($r->match($route)) {
                 $name = isset($r->options['_name']) ? $r->options['_name'] : $r->getName();
                 break;
             }
         }
         $output = [['Route name', 'URI template', 'Defaults'], [$name, $url, json_encode($route)]];
         $this->helper('table')->output($output);
         $this->out();
     } catch (MissingRouteException $e) {
         $this->err("<warning>'{$url}' did not match any routes.</warning>");
         $this->out();
         return false;
     }
 }
开发者ID:CakeDC,项目名称:cakephp,代码行数:25,代码来源:RoutesShell.php

示例12: makeTrail

 /**
  * @param string $label
  * @param \Cake\View\Helper\HtmlHelper $htmlHelper
  *
  * In order to make a trail of breadcrumbs we must:
  * 1. Emit any number of trail elements, in a view, using $htmlHelper->addCrumb().
  * 2. Emit the beginning of the trail in a layout, using $thmlHelper->getCrumbs().
  * 3. addCrumbs and getCrumbs provide the necessary information so that when the time
  *    comes to actually render the trail, the Cake software can do this.
  *
  * The problem with this plan is that some views can be reached via more than one path.
  * How can the view know which path led to it?  The basic answer is to save a path
  * in the session, with each step towards a particular view, and use that path to
  * generate the trail using a suitable number of invocations of addCrumb.  Each view's
  * url is added to the session trail, as well as a suitable label to be used in the trail.
  */
 public function makeTrail($label, $htmlHelper)
 {
     // 1. Read the present trail or init if none.
     $sessionVar = 'breadcrumbs';
     //$this->request->session()->delete($sessionVar);
     $sessionCrumbs = $this->request->session()->read($sessionVar);
     if (is_null($sessionCrumbs)) {
         $sessionCrumbs = [];
     }
     // 2. Get the present url and parse into a parameter array
     $requestUrl = $this->request->url;
     $requestUrlParams = \Cake\Routing\Router::parse($requestUrl);
     // 3. Build a new trail array by looking for the existing
     // url in the existing trail array.  This effectively removes
     // any elements of the existing trail array, that are after the
     // present url.
     $newArray = [];
     foreach ($sessionCrumbs as $key => $crumb) {
         if ($key == $requestUrl) {
             break;
         } else {
             $newArray[$key] = $crumb;
         }
     }
     // 3.1 Whether this is new or the last item matched, add it here
     $newArray[$requestUrl] = ['label' => $label, 'params' => $requestUrlParams];
     // 4. Save the trail to the session
     $this->request->session()->write($sessionVar, $newArray);
     // 5. Now add the crumbs the ordinary way
     foreach ($newArray as $key => $crumb) {
         if ($key == $requestUrl) {
             break;
         }
         // no crumb for this url
         $htmlHelper->addCrumb($crumb['label'], $crumb['params']);
     }
 }
开发者ID:bostontrader,项目名称:duncemaster,代码行数:53,代码来源:BreadcrumbHelper.php

示例13: testUsingCustomRouteClass

 /**
  * test using a custom route class for route connection
  *
  * @return void
  */
 public function testUsingCustomRouteClass()
 {
     Plugin::load('TestPlugin');
     Router::connect('/:slug', ['plugin' => 'TestPlugin', 'action' => 'index'], ['routeClass' => 'PluginShortRoute', 'slug' => '[a-z_-]+']);
     $result = Router::parse('/the-best');
     $expected = ['plugin' => 'TestPlugin', 'controller' => 'TestPlugin', 'action' => 'index', 'slug' => 'the-best', 'pass' => [], '_matchedRoute' => '/:slug'];
     $this->assertEquals($expected, $result);
 }
开发者ID:rashmi,项目名称:newrepo,代码行数:13,代码来源:RouterTest.php

示例14: urlAllowed

 /**
  * Checks whether the user is allowed to access a specific URL
  *
  * @param array $user user to check with
  * @param array|string $url url to check
  * @return void
  */
 public function urlAllowed($user, $url)
 {
     if (empty($url)) {
         return false;
     }
     if (is_array($url)) {
         // prevent plugin confusion
         $url = Hash::merge(['plugin' => null], $url);
         $url = Router::url($url);
         // strip off the base path
         $url = Router::normalize($url);
     }
     $route = Router::parse($url);
     if (empty($route['controller']) || empty($route['action'])) {
         return false;
     }
     return $this->isAuthorized($user, $route['plugin'], $route['controller'], $route['action']);
 }
开发者ID:codekanzlei,项目名称:cake-auth-actions,代码行数:25,代码来源:AuthActions.php

示例15: testRedirectUrlWithBaseSet

 /**
  * test that the returned URL doesn't contain the base URL.
  *
  * @see https://cakephp.lighthouseapp.com/projects/42648/tickets/3922-authcomponentredirecturl-prepends-appbaseurl
  *
  * @return void This test method doesn't return anything.
  */
 public function testRedirectUrlWithBaseSet()
 {
     $App = Configure::read('App');
     Configure::write('App', ['dir' => APP_DIR, 'webroot' => 'webroot', 'base' => false, 'baseUrl' => '/cake/index.php']);
     $url = '/users/login';
     $this->Auth->request = $this->Controller->request = new Request($url);
     $this->Auth->request->addParams(Router::parse($url));
     $this->Auth->request->url = Router::normalize($url);
     Router::setRequestInfo($this->Auth->request);
     $this->Auth->config('loginAction', ['controller' => 'users', 'action' => 'login']);
     $this->Auth->config('loginRedirect', ['controller' => 'users', 'action' => 'home']);
     $result = $this->Auth->redirectUrl();
     $this->assertEquals('/users/home', $result);
     $this->assertFalse($this->Auth->session->check('Auth.redirect'));
     Configure::write('App', $App);
     Router::reload();
 }
开发者ID:Rabp9,项目名称:test-psi2,代码行数:24,代码来源:AuthComponentTest.php


注:本文中的Cake\Routing\Router::parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。