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


PHP Router::popRequest方法代码示例

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


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

示例1: testUrlWithRequestAction

 /**
  * Test that Router::url() uses the first request
  */
 public function testUrlWithRequestAction()
 {
     Router::connect('/:controller', array('action' => 'index'));
     Router::connect('/:controller/:action');
     $firstRequest = new Request('/posts/index');
     $firstRequest->addParams(array('plugin' => null, 'controller' => 'posts', 'action' => 'index'))->addPaths(array('base' => ''));
     $secondRequest = new Request('/posts/index');
     $secondRequest->addParams(array('requested' => 1, 'plugin' => null, 'controller' => 'comments', 'action' => 'listing'))->addPaths(array('base' => ''));
     Router::setRequestInfo($firstRequest);
     Router::setRequestInfo($secondRequest);
     $result = Router::url(array('_base' => false));
     $this->assertEquals('/comments/listing', $result, 'with second requests, the last should win.');
     Router::popRequest();
     $result = Router::url(array('_base' => false));
     $this->assertEquals('/posts', $result, 'with second requests, the last should win.');
     // Make sure that popping an empty request doesn't fail.
     Router::popRequest();
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:21,代码来源:RouterTest.php

示例2: requestAction


//.........这里部分代码省略.........
  *
  * You can also pass the URL as an array:
  *
  * ```
  * $vars = $this->requestAction(['controller' => 'articles', 'action' => 'popular']);
  * ```
  *
  * ### Passing other request data
  *
  * You can pass POST, GET, COOKIE and other data into the request using the appropriate keys.
  * Cookies can be passed using the `cookies` key. Get parameters can be set with `query` and post
  * data can be sent using the `post` key.
  *
  * ```
  * $vars = $this->requestAction('/articles/popular', [
  *   'query' => ['page' => 1],
  *   'cookies' => ['remember_me' => 1],
  * ]);
  * ```
  *
  * ### Sending environment or header values
  *
  * By default actions dispatched with this method will use the global $_SERVER and $_ENV
  * values. If you want to override those values for a request action, you can specify the values:
  *
  * ```
  * $vars = $this->requestAction('/articles/popular', [
  *   'environment' => ['CONTENT_TYPE' => 'application/json']
  * ]);
  * ```
  *
  * ### Transmitting the session
  *
  * By default actions dispatched with this method will use the standard session object.
  * If you want a particular session instance to be used, you need to specify it.
  *
  * ```
  * $vars = $this->requestAction('/articles/popular', [
  *   'session' => new Session($someSessionConfig)
  * ]);
  * ```
  *
  * @param string|array $url String or array-based url.  Unlike other url arrays in CakePHP, this
  *    url will not automatically handle passed arguments in the $url parameter.
  * @param array $extra if array includes the key "return" it sets the autoRender to true.  Can
  *    also be used to submit GET/POST data, and passed arguments.
  * @return mixed Boolean true or false on success/failure, or contents
  *    of rendered action if 'return' is set in $extra.
  */
 public function requestAction($url, array $extra = [])
 {
     if (empty($url)) {
         return false;
     }
     if (($index = array_search('return', $extra)) !== false) {
         $extra['return'] = 0;
         $extra['autoRender'] = 1;
         unset($extra[$index]);
     }
     $extra += ['autoRender' => 0, 'return' => 1, 'bare' => 1, 'requested' => 1];
     $baseUrl = Configure::read('App.fullBaseUrl');
     if (is_string($url) && strpos($url, $baseUrl) === 0) {
         $url = Router::normalize(str_replace($baseUrl, '', $url));
     }
     if (is_string($url)) {
         $params = ['url' => $url];
     } elseif (is_array($url)) {
         $defaultParams = ['plugin' => null, 'controller' => null, 'action' => null];
         $params = ['params' => $url + $defaultParams, 'base' => false, 'url' => Router::reverse($url)];
         if (empty($params['params']['pass'])) {
             $params['params']['pass'] = [];
         }
     }
     $current = Router::getRequest();
     if ($current) {
         $params['base'] = $current->base;
         $params['webroot'] = $current->webroot;
     }
     $params['post'] = $params['query'] = [];
     if (isset($extra['post'])) {
         $params['post'] = $extra['post'];
     }
     if (isset($extra['query'])) {
         $params['query'] = $extra['query'];
     }
     if (isset($extra['cookies'])) {
         $params['cookies'] = $extra['cookies'];
     }
     if (isset($extra['environment'])) {
         $params['environment'] = $extra['environment'] + $_SERVER + $_ENV;
     }
     unset($extra['environment'], $extra['post'], $extra['query']);
     $params['session'] = isset($extra['session']) ? $extra['session'] : new Session();
     $request = new Request($params);
     $request->addParams($extra);
     $dispatcher = DispatcherFactory::create();
     $result = $dispatcher->dispatch($request, new Response());
     Router::popRequest();
     return $result;
 }
开发者ID:CakeDC,项目名称:cakephp,代码行数:101,代码来源:RequestActionTrait.php

示例3: requestAction


//.........这里部分代码省略.........
  *   'query' => ['page' => 1],
  *   'cookies' => ['remember_me' => 1],
  * ]);
  * ```
  *
  * ### Sending environment or header values
  *
  * By default actions dispatched with this method will use the global $_SERVER and $_ENV
  * values. If you want to override those values for a request action, you can specify the values:
  *
  * ```
  * $vars = $this->requestAction('/articles/popular', [
  *   'environment' => ['CONTENT_TYPE' => 'application/json']
  * ]);
  * ```
  *
  * ### Transmitting the session
  *
  * By default actions dispatched with this method will use the standard session object.
  * If you want a particular session instance to be used, you need to specify it.
  *
  * ```
  * $vars = $this->requestAction('/articles/popular', [
  *   'session' => new Session($someSessionConfig)
  * ]);
  * ```
  *
  * @param string|array $url String or array-based url.  Unlike other url arrays in CakePHP, this
  *    url will not automatically handle passed arguments in the $url parameter.
  * @param array $extra if array includes the key "return" it sets the autoRender to true.  Can
  *    also be used to submit GET/POST data, and passed arguments.
  * @return mixed Boolean true or false on success/failure, or contents
  *    of rendered action if 'return' is set in $extra.
  * @deprecated 3.3.0 You should refactor your code to use View Cells instead of this method.
  */
 public function requestAction($url, array $extra = [])
 {
     if (empty($url)) {
         return false;
     }
     if (($index = array_search('return', $extra)) !== false) {
         $extra['return'] = 0;
         $extra['autoRender'] = 1;
         unset($extra[$index]);
     }
     $extra += ['autoRender' => 0, 'return' => 1, 'bare' => 1, 'requested' => 1];
     $baseUrl = Configure::read('App.fullBaseUrl');
     if (is_string($url) && strpos($url, $baseUrl) === 0) {
         $url = Router::normalize(str_replace($baseUrl, '', $url));
     }
     if (is_string($url)) {
         $params = ['url' => $url];
     } elseif (is_array($url)) {
         $defaultParams = ['plugin' => null, 'controller' => null, 'action' => null];
         $params = ['params' => $url + $defaultParams, 'base' => false, 'url' => Router::reverse($url)];
         if (empty($params['params']['pass'])) {
             $params['params']['pass'] = [];
         }
     }
     $current = Router::getRequest();
     if ($current) {
         $params['base'] = $current->base;
         $params['webroot'] = $current->webroot;
     }
     $params['post'] = $params['query'] = [];
     if (isset($extra['post'])) {
         $params['post'] = $extra['post'];
     }
     if (isset($extra['query'])) {
         $params['query'] = $extra['query'];
     }
     if (isset($extra['cookies'])) {
         $params['cookies'] = $extra['cookies'];
     }
     if (isset($extra['environment'])) {
         $params['environment'] = $extra['environment'] + $_SERVER + $_ENV;
     }
     unset($extra['environment'], $extra['post'], $extra['query']);
     $params['session'] = isset($extra['session']) ? $extra['session'] : new Session();
     $request = new Request($params);
     $request->addParams($extra);
     $dispatcher = DispatcherFactory::create();
     // If an application is using PSR7 middleware,
     // we need to 'fix' their missing dispatcher filters.
     $needed = ['routing' => RoutingFilter::class, 'controller' => ControllerFactoryFilter::class];
     foreach ($dispatcher->filters() as $filter) {
         if ($filter instanceof RoutingFilter) {
             unset($needed['routing']);
         }
         if ($filter instanceof ControllerFactoryFilter) {
             unset($needed['controller']);
         }
     }
     foreach ($needed as $class) {
         $dispatcher->addFilter(new $class());
     }
     $result = $dispatcher->dispatch($request, new Response());
     Router::popRequest();
     return $result;
 }
开发者ID:nrother,项目名称:cakephp,代码行数:101,代码来源:RequestActionTrait.php

示例4: requestAction

 /**
  * Calls a controller's method from any location. Can be used to connect controllers together
  * or tie plugins into a main application. requestAction can be used to return rendered views
  * or fetch the return value from controller actions.
  *
  * Under the hood this method uses Router::reverse() to convert the $url parameter into a string
  * URL. You should use URL formats that are compatible with Router::reverse()
  *
  * ### Examples
  *
  * A basic example getting the return value of the controller action:
  *
  * {{{
  * $variables = $this->requestAction('/articles/popular');
  * }}}
  *
  * A basic example of request action to fetch a rendered page without the layout.
  *
  * {{{
  * $viewHtml = $this->requestAction('/articles/popular', ['return']);
  * }}}
  *
  * You can also pass the URL as an array:
  *
  * {{{
  * $vars = $this->requestAction(['controller' => 'articles', 'action' => 'popular']);
  * }}}
  *
  * ### Passing other request data
  *
  * You can pass POST, GET, COOKIE and other data into the request using the apporpriate keys.
  * Cookies can be passed using the `cookies` key. Get parameters can be set with `query` and post
  * data can be sent using the `post` key.
  *
  * {{{
  * $vars = $this->requestAction('/articles/popular', [
  *   'query' => ['page' = > 1],
  *   'cookies' => ['remember_me' => 1],
  * ]);
  * }}}
  *
  * @param string|array $url String or array-based url.  Unlike other url arrays in CakePHP, this
  *    url will not automatically handle passed arguments in the $url parameter.
  * @param array $extra if array includes the key "return" it sets the autoRender to true.  Can
  *    also be used to submit GET/POST data, and passed arguments.
  * @return mixed Boolean true or false on success/failure, or contents
  *    of rendered action if 'return' is set in $extra.
  */
 public function requestAction($url, array $extra = array())
 {
     if (empty($url)) {
         return false;
     }
     if (($index = array_search('return', $extra)) !== false) {
         $extra['return'] = 0;
         $extra['autoRender'] = 1;
         unset($extra[$index]);
     }
     $extra = array_merge(['autoRender' => 0, 'return' => 1, 'bare' => 1, 'requested' => 1], $extra);
     $post = $query = [];
     if (isset($extra['post'])) {
         $post = $extra['post'];
     }
     if (isset($extra['query'])) {
         $query = $extra['query'];
     }
     unset($extra['post'], $extra['query']);
     if (is_string($url) && strpos($url, Configure::read('App.fullBaseUrl')) === 0) {
         $url = Router::normalize(str_replace(Configure::read('App.fullBaseUrl'), '', $url));
     }
     if (is_string($url)) {
         $params = ['url' => $url];
     } elseif (is_array($url)) {
         $params = array_merge($url, ['pass' => [], 'base' => false, 'url' => Router::reverse($url)]);
     }
     if (!empty($post)) {
         $params['post'] = $post;
     }
     if (!empty($query)) {
         $params['query'] = $query;
     }
     $request = new Request($params);
     $dispatcher = new Dispatcher();
     $result = $dispatcher->dispatch($request, new Response(), $extra);
     Router::popRequest();
     return $result;
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:87,代码来源:RequestActionTrait.php


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