setExtensions() публичный статический Метод

To have the extensions parsed you still need to call Router::parseExtensions()
public static setExtensions ( array $extensions, boolean $merge = true ) : array
$extensions array List of extensions to be added as valid extension
$merge boolean Default true will merge extensions. Set to false to override current extensions
Результат array
 /**
  * Test that ext is set to the first listed extension with multiple accepted
  * content types.
  * Having multiple types accepted with same weight, means the client lets the
  * server choose the returned content type.
  *
  * @return void
  */
 public function testInitializeNoContentTypeWithMultipleAcceptedTypes()
 {
     $_SERVER['HTTP_ACCEPT'] = 'application/json, application/javascript, application/xml, */*; q=0.01';
     $this->assertNull($this->RequestHandler->ext);
     Router::parseExtensions('xml', 'json');
     $this->RequestHandler->initialize($this->Controller);
     $this->assertEquals('xml', $this->RequestHandler->ext);
     $this->RequestHandler->ext = null;
     Router::setExtensions(array('json', 'xml'), false);
     $this->RequestHandler->initialize($this->Controller);
     $this->assertEquals('json', $this->RequestHandler->ext);
 }
Пример #2
0
 *
 * PHP 5
 *
 * CakePHP(tm) : 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(tm) Project
 * @package       app.Config
 * @since         CakePHP(tm) v 0.2.9
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 */
Router::parseExtensions();
Router::setExtensions(array('json'));
Router::connect('/', array('controller' => 'boards', 'action' => 'all'));
Router::connect('/login', array('controller' => 'sessions', 'action' => 'login'));
Router::connect('/logout', array('controller' => 'sessions', 'action' => 'logout'));
Router::connect('/dashboard', array('controller' => 'users', 'action' => 'dashboard'));
Router::connect('/teams', array('controller' => 'users', 'action' => 'random_teams'));
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
if (AuthComponent::user()) {
    // authenticated routes
} else {
    // unauthenticated routes
}
CakePlugin::routes();
require CAKE . 'Config' . DS . 'routes.php';
Пример #3
0
 /**
  * testSetExtensions method
  *
  * @return void
  */
 public function testSetExtensions()
 {
     Router::setExtensions(array('rss'));
     $this->assertEquals(array('rss'), Router::extensions());
     require CAKE . 'Config' . DS . 'routes.php';
     $result = Router::parse('/posts.rss');
     $this->assertFalse(isset($result['ext']));
     Router::parseExtensions();
     $result = Router::parse('/posts.rss');
     $this->assertEquals('rss', $result['ext']);
     $result = Router::parse('/posts.xml');
     $this->assertFalse(isset($result['ext']));
     Router::setExtensions(array('xml'));
     $result = Router::extensions();
     $this->assertEquals(array('rss', 'xml'), $result);
     $result = Router::parse('/posts.xml');
     $this->assertEquals('xml', $result['ext']);
     $result = Router::setExtensions(array('pdf'), false);
     $this->assertEquals(array('pdf'), $result);
 }
Пример #4
0
<?php

/**
 * Note: Router::setExtensions() is available since CakePHP 2.2
 * If you use 2.1 dont load this routes file, and add xls and xlsx to your parseExtensions() in app/Config/routes.php
 */
Router::parseExtensions();
Router::setExtensions(array('xls', 'xlsx'));
Пример #5
0
<?php

/**
 * Route's defaults.
 *
 * @var array
 */
$defaults = array('plugin' => 'webmaster', 'controller' => 'webmaster');
/**
 * Force usage of the CakeRoute class to avoid duplicates that are useless anyways
 * (i.e. /fr/sitemap.xml, /sp/robots.txt).
 *
 * @var array
 */
$options = array('routeClass' => 'CakeRoute');
/**
 * Add the `txt` and `xml` extensions.
 */
Router::setExtensions(array('txt', 'xml'));
/**
 * Route `/robots.txt`.
 */
Router::connect('/robots', array_merge($defaults, array('action' => 'robots', 'ext' => 'txt')), $options);
Router::promote();
/**
 * Route `/sitemap.xml`.
 */
Router::connect('/sitemap', array_merge($defaults, array('action' => 'sitemap', 'ext' => 'xml')), $options);
Router::promote();
unset($options, $defaults);
Пример #6
0
<?php

Router::parseExtensions();
Router::setExtensions(array('json', 'xml', 'csv', 'rss', 'pdf'));
Router::connect('/', array('controller' => 'overview', 'action' => 'index'));
Router::connect('/register', array('controller' => 'account', 'action' => 'register'));
Router::connect('/login', array('controller' => 'account', 'action' => 'login'));
Router::connect('/logout', array('controller' => 'account', 'action' => 'logout'));
//route to switch locale
//Router::connect('/lang/*', array('controller' => 'p28n', 'action' => 'change'));
Router::connect('/admin', array('admin' => 'admin', 'controller' => 'overview', 'action' => 'index'));
//Router::connect('/translate', array('plugin' => 'translate', 'controller' => 'translate_groups', 'action' => 'overview'));
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
CakePlugin::routes();
/**
 * Load the CakePHP default routes. Only remove this if you do not want to use
 * the built-in default routes.
 */
require CAKE . 'Config' . DS . 'routes.php';
Пример #7
0
 * @package       app.Config
 * @since         CakePHP(tm) v 0.2.9
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
 */
/**
 * Here, we are connecting '/' (base path) to controller called 'Pages',
 * its action called 'display', and we pass a param to select the view file
 * to use (in this case, /app/View/Pages/home.ctp)...
 */
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
/**
 * ...and connect the rest of 'Pages' controller's URLs.
 */
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
/**
 * Load all plugin routes. See the CakePlugin documentation on
 * how to customize the loading of plugin routes.
 */
CakePlugin::routes();
/**
 * Load all plugin routes. See the CakePlugin documentation on
 * how to customize the loading of plugin routes.
 */
CakePlugin::routes();
Router::setExtensions(array('json'), true);
Router::parseExtensions('json');
/**
 * Load the CakePHP default routes. Only remove this if you do not want to use
 * the built-in default routes.
 */
require CAKE . 'Config' . DS . 'routes.php';
Пример #8
0
<?php

/**
 * Note: Router::setExtensions() is available since CakePHP 2.2
 * If you use 2.1 dont load this routes file, and add pdf to your parseExtensions() in app/Config/routes.php
 */
Router::parseExtensions();
Router::setExtensions(array('pdf'));