當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Router::extensions方法代碼示例

本文整理匯總了PHP中Cake\Routing\Router::extensions方法的典型用法代碼示例。如果您正苦於以下問題:PHP Router::extensions方法的具體用法?PHP Router::extensions怎麽用?PHP Router::extensions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Cake\Routing\Router的用法示例。


在下文中一共展示了Router::extensions方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: __construct

 /**
  * Constructor
  *
  * @param \Cake\Network\Request $request Request instance.
  * @param \Cake\Network\Response $response Reponse instance.
  */
 public function __construct($request = null, $response = null)
 {
     parent::__construct($request, $response);
     if (count(Router::extensions()) && !isset($this->RequestHandler)) {
         $this->loadComponent('RequestHandler');
     }
     $eventManager = $this->eventManager();
     if (isset($this->Auth)) {
         $eventManager->detach($this->Auth);
     }
     if (isset($this->Security)) {
         $eventManager->detach($this->Security);
     }
     $this->cacheAction = false;
     $this->viewPath = 'Error';
 }
開發者ID:maitrepylos,項目名稱:nazeweb,代碼行數:22,代碼來源:ErrorController.php

示例2: setUp

 /**
  * [setUp description]
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $this->resetReflectionCache();
     $this->_eventManager = EventManager::instance();
     $existing = Configure::read('App.paths.templates');
     $existing[] = Plugin::path('Crud') . 'tests/App/Template/';
     Configure::write('App.paths.templates', $existing);
     Configure::write('App.namespace', 'Crud\\Test\\App');
     Router::extensions('json');
     Router::connect('/:controller', ['action' => 'index'], ['routeClass' => 'DashedRoute']);
     Router::connect('/:controller/:action/*', [], ['routeClass' => 'DashedRoute']);
     $this->useHttpServer(false);
 }
開發者ID:friendsofcake,項目名稱:crud,代碼行數:19,代碼來源:IntegrationTestCase.php

示例3: __construct

 /**
  * Constructor
  *
  * @param \Cake\Network\Request|null $request Request instance.
  * @param \Cake\Network\Response|null $response Response instance.
  */
 public function __construct($request = null, $response = null)
 {
     parent::__construct($request, $response);
     if (count(Router::extensions()) && !isset($this->RequestHandler)) {
         $this->loadComponent('RequestHandler');
     }
     $eventManager = $this->eventManager();
     if (isset($this->Auth)) {
         $eventManager->off($this->Auth);
     }
     if (isset($this->Security)) {
         $eventManager->off($this->Security);
     }
 }
開發者ID:CakeDC,項目名稱:cakephp,代碼行數:20,代碼來源:ErrorController.php

示例4: testReverseWithExtension

 /**
  * Test that extensions work with Router::reverse()
  *
  * @return void
  */
 public function testReverseWithExtension()
 {
     Router::connect('/:controller/:action/*');
     Router::extensions('json', false);
     $request = new Request('/posts/view/1.json');
     $request->addParams(array('controller' => 'posts', 'action' => 'view', 'pass' => array(1), '_ext' => 'json'));
     $request->query = [];
     $result = Router::reverse($request);
     $expected = '/posts/view/1.json';
     $this->assertEquals($expected, $result);
 }
開發者ID:maitrepylos,項目名稱:nazeweb,代碼行數:16,代碼來源:RouterTest.php

示例5: testSetExtensions

 /**
  * testSetExtensions method
  *
  * @return void
  */
 public function testSetExtensions()
 {
     Router::extensions();
     Router::parseExtensions('rss', false);
     $this->assertContains('rss', Router::extensions());
     require CAKE . 'Config/routes.php';
     $result = Router::parse('/posts.rss');
     $this->assertEquals('rss', $result['_ext']);
     $result = Router::parse('/posts.xml');
     $this->assertFalse(isset($result['_ext']));
     Router::parseExtensions(array('xml'));
     $result = Router::extensions();
     $this->assertContains('rss', $result);
     $this->assertContains('xml', $result);
     $result = Router::parse('/posts.xml');
     $this->assertEquals('xml', $result['_ext']);
     $result = Router::parseExtensions(array('pdf'), false);
     $this->assertEquals(array('pdf'), $result);
 }
開發者ID:ripzappa0924,項目名稱:carte0.0.1,代碼行數:24,代碼來源:RouterTest.php

示例6:

     * Connect catchall routes for all controllers.
     *
     * Using the argument `DashedRoute`, the `fallbacks` method is a shortcut for
     *    `$routes->connect('/:controller', ['action' => 'index'], ['routeClass' => 'DashedRoute']);`
     *    `$routes->connect('/:controller/:action/*', [], ['routeClass' => 'DashedRoute']);`
     *
     * Any route class can be used with this method, such as:
     * - DashedRoute
     * - InflectedRoute
     * - Route
     * - Or your own route class
     *
     * You can remove these routes once you've connected the
     * routes you want in your application.
     */
    //$routes->fallbacks('DashedRoute');
    /**    
     * map controller resources
     */
    Router::mapResources('users');
    Router::mapResources('books');
    Router::mapResources('authors');
    Router::mapResources('BookIssues');
    Router::mapResources('geners');
    Router::extensions(['json', 'xml']);
});
/**
 * Load all plugin routes.  See the Plugin documentation on
 * how to customize the loading of plugin routes.
 */
Plugin::routes();
開發者ID:BharadhwajGummadi,項目名稱:library,代碼行數:31,代碼來源:routes.php

示例7: function

 * to set as the default:
 *
 * - Route
 * - InflectedRoute
 * - 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::extensions('json');
Router::scope('/', function ($routes) {
    /**
     * Here, we are connecting '/' (base path) to a controller called 'Pages',
     * its action called 'display', and we pass a param to select the view file
     * to use (in this case, src/Template/Pages/home.ctp)...
     */
    $routes->connect('/', ['controller' => 'Prognostics', 'action' => 'home']);
    /**
     * ...and connect the rest of 'Pages' controller's URLs.
     */
    $routes->connect('/*', ['controller' => 'Pages', 'action' => 'page404']);
    $routes->connect('/prognostic/:id', ['controller' => 'Prognostics', 'action' => 'pronostic'], ['id' => '\\d+', 'pass' => ['id']]);
    $routes->connect('/ticket/:id/:match', ['controller' => 'Prognostics', 'action' => 'ticket'], ['id' => '\\d+', 'match' => '\\w+', 'pass' => ['id', 'match']]);
    $routes->connect('/cgu', ['controller' => 'Pages', 'action' => 'cgu']);
    $routes->connect('/login', ['controller' => 'Users', 'action' => 'login']);
開發者ID:laurentdamien,項目名稱:sportlay,代碼行數:31,代碼來源:routes.php

示例8: testNoViewClassExtension

 /**
  * test configured extension but no view class set.
  *
  * @return void
  * @triggers Controller.beforeRender $this->Controller
  */
 public function testNoViewClassExtension()
 {
     Router::extensions(['json', 'xml', 'ajax', 'csv'], false);
     $this->Controller->request->params['_ext'] = 'csv';
     $event = new Event('Controller.startup', $this->Controller);
     $this->RequestHandler->initialize([]);
     $this->RequestHandler->startup($event);
     $this->Controller->eventManager()->on('Controller.beforeRender', function () {
         return $this->Controller->response;
     });
     $this->Controller->render();
     $this->assertEquals('RequestHandlerTest' . DS . 'csv', $this->Controller->viewBuilder()->templatePath());
     $this->assertEquals('csv', $this->Controller->viewBuilder()->layoutPath());
 }
開發者ID:Slayug,項目名稱:castor,代碼行數:20,代碼來源:RequestHandlerComponentTest.php

示例9: testScopeExtensionsContained

 /**
  * Test to ensure that extensions defined in scopes don't leak.
  * And that global extensions are propagated.
  *
  * @return void
  */
 public function testScopeExtensionsContained()
 {
     Router::extensions(['json']);
     Router::scope('/', function ($routes) {
         $this->assertEquals(['json'], $routes->extensions(), 'Should default to global extensions.');
         $routes->extensions(['rss']);
         $this->assertEquals(['rss'], $routes->extensions(), 'Should include new extensions.');
         $routes->connect('/home', []);
     });
     $this->assertEquals(['json', 'rss'], array_values(Router::extensions()));
     Router::scope('/api', function ($routes) {
         $this->assertEquals(['json'], $routes->extensions(), 'Should default to global extensions.');
         $routes->extensions(['json', 'csv']);
         $routes->connect('/export', []);
         $routes->scope('/v1', function ($routes) {
             $this->assertEquals(['json', 'csv'], $routes->extensions());
         });
     });
     $this->assertEquals(['json', 'rss', 'csv'], array_values(Router::extensions()));
 }
開發者ID:rashmi,項目名稱:newrepo,代碼行數:26,代碼來源:RouterTest.php

示例10: function

 * to set as the default:
 *
 * - Route
 * - InflectedRoute
 * - 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::extensions(['csv', 'json', 'html']);
Router::scope('/', function ($routes) {
    /**
     * Here, we are connecting '/' (base path) to a controller called 'Pages',
     * its action called 'display', and we pass a param to select the view file
     * to use (in this case, src/Template/Pages/home.ctp)...
     */
    $routes->connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']);
    //Just as an example. Might not bother keeping custom routes like this:
    $routes->connect('/create', ['controller' => 'Clubs', 'action' => 'create']);
    /**
     * ...and connect the rest of 'Pages' controller's URLs.
     */
    $routes->connect('/pages/*', ['controller' => 'Pages', 'action' => 'display']);
    /**
     * Catching urls based on old system. Can delete later
開發者ID:byu-oit-appdev,項目名稱:byusa-clubs,代碼行數:31,代碼來源:routes.php

示例11: function

<?php

use Cake\Routing\Router;
Router::extensions(['html', 'json']);
Router::plugin('BoxManager', ['path' => '/box-manager'], function ($routes) {
    $routes->connect('/login', ['controller' => 'Users', 'action' => 'login']);
    $routes->fallbacks('DashedRoute');
});
Router::prefix('admin', function ($routes) {
    $routes->plugin('BoxManager', ['path' => '/box-manager'], function ($routes) {
        $routes->fallbacks('DashedRoute');
    });
    $routes->fallbacks('DashedRoute');
});
開發者ID:Aerue,項目名稱:avalia,代碼行數:14,代碼來源:routes.php

示例12: testInitializeContentTypeAndExtensionMismatch

 /**
  * Test that a type mismatch doesn't incorrectly set the ext
  *
  * @return void
  */
 public function testInitializeContentTypeAndExtensionMismatch()
 {
     $event = new Event('Controller.initialize', $this->Controller);
     $this->assertNull($this->RequestHandler->ext);
     $extensions = Router::extensions();
     Router::parseExtensions('xml', false);
     $this->Controller->request = $this->getMock('Cake\\Network\\Request', ['accepts']);
     $this->Controller->request->expects($this->any())->method('accepts')->will($this->returnValue(array('application/json')));
     $this->RequestHandler->initialize($event);
     $this->assertNull($this->RequestHandler->ext);
     call_user_func_array(array('Cake\\Routing\\Router', 'parseExtensions'), [$extensions, false]);
 }
開發者ID:ripzappa0924,項目名稱:carte0.0.1,代碼行數:17,代碼來源:RequestHandlerComponentTest.php

示例13: function

 * to set as the default:
 *
 * - Route
 * - InflectedRoute
 * - 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::extensions(['json', 'xml', 'text', 'html']);
Router::scope('/', function ($routes) {
    /**
     * Here, we are connecting '/' (base path) to a controller called 'Pages',
     * its action called 'display', and we pass a param to select the view file
     * to use (in this case, src/Template/Pages/home.ctp)...
     */
    $routes->connect('/', ['controller' => 'Export', 'action' => 'test']);
    /**
     * ...and connect the rest of 'Pages' controller's URLs.
     */
    $routes->connect('/pages/*', ['controller' => 'Pages', 'action' => 'display']);
    /**
     * Connect catchall routes for all controllers.
     *
     * Using the argument `InflectedRoute`, the `fallbacks` method is a shortcut for
開發者ID:Kaju-Bubanja,項目名稱:GSOA,代碼行數:31,代碼來源:routes.php

示例14:

<?php

use Cake\Routing\Router;
Router::extensions('csv');
開發者ID:friendsofcake,項目名稱:cakephp-csvview,代碼行數:4,代碼來源:routes.php

示例15:

<?php

use Cake\Routing\Router;
Router::extensions(['rss']);
開發者ID:jxav,項目名稱:cakephp-feed,代碼行數:4,代碼來源:bootstrap.php


注:本文中的Cake\Routing\Router::extensions方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。