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


PHP Router::addUrlFilter方法代码示例

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


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

示例1: __construct

 /**
  * Constructor.
  *
  * We tweak Field UI here, as contents are polymorphic we need to dynamically
  * change `$_manageTable` property according to `content_type`.
  *
  * @param \Cake\Network\Request $request Request object for this controller. Can
  *  be null for testing, but expect that features that use the request
  *  parameters will not work.
  * @param \Cake\Network\Response $response Response object for this controller.
  */
 public function __construct($request = null, $response = null)
 {
     parent::__construct($request, $response);
     $validTypes = quickapps('content_types');
     if (!isset($request->query['type']) || !in_array($request->query['type'], $validTypes)) {
         $this->redirect(['plugin' => 'System', 'controller' => 'dashboard', 'prefix' => 'admin']);
     } else {
         // allows to manage polymorphic entities
         $this->_bundle = $request->query['type'];
         // Make $_GET['type'] persistent
         Router::addUrlFilter(function ($params, $request) {
             if (isset($request->query['type'])) {
                 $params['type'] = $request->query['type'];
             }
             return $params;
         });
     }
 }
开发者ID:quickapps-plugins,项目名称:content,代码行数:29,代码来源:FieldsController.php

示例2: beforeFilter

 /**
  * {@inheritDoc}
  *
  * @param \Cake\Event\Event $event The event that was triggered
  * @return void
  */
 public function beforeFilter(Event $event)
 {
     if (is_readable(ROOT . '/config/settings.php')) {
         $this->redirect('/');
     }
     $this->_prepareLayout();
     $this->viewBuilder()->className('CMS\\View\\View')->theme(false)->layout('Installer.startup')->helpers(['Menu.Menu']);
     if (!empty($this->request->query['locale']) && !in_array($this->request->params['action'], ['language', 'index'])) {
         I18n::locale($this->request->query['locale']);
         $this->request->session()->write('installation.language', I18n::locale());
     } elseif ($this->request->session()->read('installation.language')) {
         I18n::locale($this->request->session()->read('installation.language'));
     }
     Router::addUrlFilter(function ($params, $request) {
         if (!in_array($request->params['action'], ['language', 'index'])) {
             $params['locale'] = I18n::locale();
         }
         return $params;
     });
 }
开发者ID:quickapps-plugins,项目名称:installer,代码行数:26,代码来源:StartupController.php

示例3: testUrlGenerationWithUrlFilter

 /**
  * Test that url filters are applied to url params.
  *
  * @return void
  */
 public function testUrlGenerationWithUrlFilter()
 {
     Router::connect('/:lang/:controller/:action/*');
     $request = new Request();
     $request->addParams(array('lang' => 'en', 'controller' => 'posts', 'action' => 'index'))->addPaths(array('base' => '', 'here' => '/'));
     Router::pushRequest($request);
     $calledCount = 0;
     Router::addUrlFilter(function ($url, $request) use(&$calledCount) {
         $calledCount++;
         $url['lang'] = $request->lang;
         return $url;
     });
     Router::addUrlFilter(function ($url, $request) use(&$calledCount) {
         $calledCount++;
         $url[] = '1234';
         return $url;
     });
     $result = Router::url(array('controller' => 'tasks', 'action' => 'edit'));
     $this->assertEquals('/en/tasks/edit/1234', $result);
     $this->assertEquals(2, $calledCount);
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:26,代码来源:RouterTest.php

示例4: elseif

 * - DashedRoute
 *
 * If no call is made to `Router::defaultRouteClass`, the class used is
 * `Route` (`Cake\Routing\Route\Route`)
 *
 * Note that `Route` does not do any inflections on URLs which will result in
 * inconsistently cased URLs when used with `:plugin`, `:controller` and
 * `:action` markers.
 *
 */
Router::defaultRouteClass('Route');
Router::addUrlFilter(function ($params, $request) {
    if (isset($request->params['lang']) && !isset($params['lang'])) {
        $params['lang'] = $request->params['lang'];
    } elseif (!isset($params['lang'])) {
        $params['lang'] = Router::getRequest()->session()->read('lang');
        // set your default language here
    }
    return $params;
});
$lang = 'en';
if (Router::getRequest()->session()->check('Config.language')) {
    $lang = Router::getRequest()->session()->read('Config.language');
}
Router::redirect('/', "/{$lang}/");
Router::connect('/:lang/', ['controller' => 'Home', 'action' => 'index']);
Router::connect('/:lang/:controller', ['action' => 'index']);
Router::connect('/:lang/:controller/about', ['action' => 'about']);
Router::connect('/:lang/:controller/search', ['action' => 'search']);
Router::connect('/:lang/:controller/profile', ['action' => 'profile']);
Router::connect('/:lang/:controller/settings', ['action' => 'settings']);
开发者ID:GreeNoir,项目名称:game-wizard,代码行数:31,代码来源:routes.php


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