/** * Test that extensions work with Router::reverse() * * @return void */ public function testReverseWithExtension() { Router::connect('/:controller/:action/*'); Router::parseExtensions('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); }
/** * test configured extension but no view class set. */ public function testNoViewClassExtension() { Router::parseExtensions(['json', 'xml', 'ajax', 'csv'], false); $this->Controller->request->params['_ext'] = 'csv'; $event = new Event('Controller.startup', $this->Controller); $this->RequestHandler->initialize($event); $this->RequestHandler->startup($event); $this->assertEquals('RequestHandlerTest/csv', $this->Controller->viewPath); $this->assertEquals('csv', $this->Controller->layoutPath); }
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) * * Licensed under The MIT License * For full copyright and license information, please see the LICENSE.txt * Redistributions of files must retain the above copyright notice. * * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project * @license http://www.opensource.org/licenses/mit-license.php MIT License */ namespace App\Config; use Cake\Core\Configure; use Cake\Core\Plugin; use Cake\Routing\Router; Router::parseExtensions('json', 'xml'); /** * Uncomment the define below to use CakePHP prefix routes. * * The value of the define determines the names of the routes * and their associated controller actions: * * Set to an array of prefixes you want to use in your application. Use for * admin or other prefixed routes. * * Routing.prefixes = array('admin', 'manager'); * * Enables: * `App\Controller\Admin` and `/admin/controller/index` * `App\Controller\Manager` and `/manager/controller/index` *
<?php /** * Routes file * * Routes for test app * * CakePHP : Rapid Development Framework (http://cakephp.org) * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) * * Licensed under The MIT License * For full copyright and license information, please see the LICENSE.txt * Redistributions of files must retain the above copyright notice. * * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP Project * @since 2.0.0 * @license http://www.opensource.org/licenses/mit-license.php MIT License */ namespace TestApp\Config; use Cake\Routing\Router; // Configure::write('Routing.prefixes', array()); Router::parseExtensions('json'); Router::connect('/some_alias', array('controller' => 'tests_apps', 'action' => 'some_method')); Router::connect('/', ['controller' => 'pages', 'action' => 'display', 'home']); require CAKE . 'Config/routes.php';