本文整理汇总了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';
}
示例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);
}
示例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);
}
}
示例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);
}
示例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);
}
示例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();
示例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']);
示例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());
}
示例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()));
}
示例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
示例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');
});
示例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]);
}
示例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
示例14:
<?php
use Cake\Routing\Router;
Router::extensions('csv');
示例15:
<?php
use Cake\Routing\Router;
Router::extensions(['rss']);