Пример #1
0
 * The following route classes are supplied with CakePHP and are appropriate
 * 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('DashedRoute');
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' => 'Projects', 'action' => 'index']);
    Router::scope('/tickets', ['Controller' => 'Tickets'], function ($routes) {
        $routes->connect('/add', ['controller' => 'Tickets', 'action' => 'add']);
        $routes->connect('/Add', ['controller' => 'Tickets', 'action' => 'add']);
        $routes->connect('/edit/*', ['controller' => 'Tickets', 'action' => 'edit']);
        $routes->connect('/Edit/*', ['controller' => 'Tickets', 'action' => 'edit']);
        $routes->connect('/view', ['controller' => 'Tickets', 'action' => 'index']);
        $routes->connect('/View', ['controller' => 'Tickets', 'action' => 'index']);
        $routes->connect('/view/*', ['controller' => 'Tickets', 'action' => 'view']);
Пример #2
0
 /**
  * Test that class must exist
  *
  * @expectedException \Cake\Error\Exception
  * @return void
  */
 public function testSettingNonExistentDefaultRouteException()
 {
     Router::defaultRouteClass('NonExistentClass');
 }
Пример #3
0
 * The following route classes are supplied with CakePHP and are appropriate
 * 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) {
    $routes->extensions(['json']);
    $routes->resources('Accesses');
    $routes->resources('Categories');
    $routes->resources('Groups');
    $routes->resources('Markers');
    $routes->resources('Markerviews');
    $routes->resources('Places');
    $routes->resources('Respondents');
    $routes->resources('Users');
    $routes->resources('Weather');
    $routes->fallbacks('InflectedRoute');
    /**
     * Here, we are connecting '/' (base path) to a controller called 'Pages',
Пример #4
0
 /**
  * Test setting default route class.
  *
  * @return void
  */
 public function testDefaultRouteClass()
 {
     Router::connect('/:controller', ['action' => 'index']);
     $result = Router::url(['controller' => 'FooBar', 'action' => 'index']);
     $this->assertEquals('/FooBar', $result);
     // This is needed because tests/boostrap.php sets App.namespace to 'App'
     Configure::write('App.namespace', 'TestApp');
     Router::defaultRouteClass('DashedRoute');
     Router::connect('/cake/:controller', ['action' => 'cake']);
     $result = Router::url(['controller' => 'FooBar', 'action' => 'cake']);
     $this->assertEquals('/cake/foo-bar', $result);
     $result = Router::url(['controller' => 'FooBar', 'action' => 'index']);
     $this->assertEquals('/FooBar', $result);
     Router::reload();
     Router::defaultRouteClass('DashedRoute');
     Router::scope('/', function ($routes) {
         $routes->fallbacks();
     });
     $result = Router::url(['controller' => 'FooBar', 'action' => 'index']);
     $this->assertEquals('/foo-bar', $result);
 }
Пример #5
0
 * The following route classes are supplied with CakePHP and are appropriate
 * 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(DashedRoute::class);
Router::scope('/', function (RouteBuilder $routes) {
    $routes->connect('/', ['controller' => 'Pages', 'action' => 'home']);
    $routes->connect('/*', ['controller' => 'Articles', 'action' => 'view']);
    $routes->connect('/blog/*', ['controller' => 'Articles', 'action' => 'index']);
    $routes->connect('/rss', ['controller' => 'Articles', 'action' => 'rss']);
    $routes->connect('/author/*', ['controller' => 'Author', 'action' => 'index']);
    $routes->connect('/category/*', ['controller' => 'Categories', 'action' => 'index']);
    $routes->connect('/search', ['controller' => 'Search', 'action' => 'index']);
    $routes->connect('/users/login', ['controller' => 'Users', 'action' => 'login']);
    $routes->connect('/users/logout', ['controller' => 'Users', 'action' => 'logout']);
    $routes->connect('/admin', ['controller' => 'Admin', 'action' => 'index']);
    $routes->connect('/install', ['controller' => 'Install', 'action' => 'index']);
    $routes->fallbacks(DashedRoute::class);
});
Router::prefix('admin', function ($routes) {
Пример #6
0
 *
 * 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
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
 */
use Cake\Core\Plugin;
use Cake\Routing\Router;
Router::extensions(['json']);
Router::defaultRouteClass('InflectedRoute');
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' => 'Todos', 'action' => 'index']);
    /**
     * ...and connect the rest of 'Pages' controller's URLs.
     */
    $routes->connect('/pages/*', ['controller' => 'Pages', 'action' => 'display']);
    /**
     * Connect a route for the index action of any controller.
     * And a more general catch all route for any action.
     *
Пример #7
0
 * The following route classes are supplied with CakePHP and are appropriate
 * 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('EntityRoute');
//Router::defaultRouteClass('Route');
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']);
    $routes->connect('/', ['controller' => 'Articles', 'action' => 'index']);
    $routes->connect('/login', ['controller' => 'Users', 'action' => 'login']);
    $routes->connect('/logout', ['controller' => 'Users', 'action' => 'logout']);
    $routes->connect('/articulos/:slug', ['controller' => 'Articles', 'action' => 'view'], ['_name' => 'articlesView', 'routeClass' => 'EntityRoute', 'pass' => ['slug']]);
    $routes->connect('/sobre/:slug', ['controller' => 'Articles', 'action' => 'view'], ['_name' => 'coreLinks', 'routeClass' => 'EntityRoute', 'pass' => ['slug']]);
    /**
     * ...and connect the rest of 'Pages' controller's URLs.
Пример #8
0
 /**
  * New route
  *
  * @param $name
  * @param $route
  */
 private static function _newRoute($name, $route)
 {
     $method = 'scope';
     $path = '/';
     $options = [];
     if (isset($route['config'])) {
         if (!is_array($route['config'])) {
             $route['config'] = self::_loadRouteConfig($route['config']);
         }
         if (isset($route['config']['plugin']) && Plugin::isLoaded($route['config']['plugin'])) {
             $method = 'plugin';
             $path = $route['config']['plugin'];
             $options = ['path' => $route['path']];
         }
     }
     // Set default route class
     if (isset($route['config']['default_route_class'])) {
         if (in_array($route['config']['default_route_class'], ['Route', 'InflectedRoute', 'DashedRoute'])) {
             Router::defaultRouteClass($route['config']['default_route_class']);
         }
     }
     // Debugging
     if (self::$_debug) {
         self::_addToDump("\\Cake\\Routing\\Router::{$method}('{$path}', " . self::_arrToStr($options) . ", function (" . '$routes' . ") {");
     }
     Router::$method($path, $options, function ($routes) use($route, $name) {
         $exclude = ['pass', 'validate', 'routes', 'extensions', 'default_route_class'];
         if (isset($route['config']) && isset($route['config']['controller'])) {
             if (isset($route['config']['extensions']) && is_array($route['config']['extensions'])) {
                 /* @var \Cake\Routing\Router $routes */
                 $routes->extensions($route['config']['extensions']);
                 if (self::$_debug) {
                     self::_addToDump("\t" . '$routes->extensions(' . self::_arrToStr($route['config']['extensions']) . ');');
                 }
             }
             $route = self::_createPassParams($route);
             $opts = [];
             foreach ($route['config'] as $key => $item) {
                 if (!in_array($key, $exclude)) {
                     $opts[$key] = $item;
                 }
             }
             $thirdParam = self::_buildThirdParam($name, $route);
             /* @var \Cake\Routing\Router $routes */
             $routes->connect('/', $opts, $thirdParam);
             // Debugging
             if (self::$_debug) {
                 self::_addToDump("\t" . '$routes->connect(\'/\', ' . self::_arrToStr($opts) . ', ' . self::_arrToStr($thirdParam) . ');');
             }
         }
         if (isset($route['config']) && isset($route['config']['routes'])) {
             foreach ($route['config']['routes'] as $key => $x) {
                 if (isset($x['extensions']) && is_array($x['extensions'])) {
                     /* @var \Cake\Routing\Router $routes */
                     $routes->extensions($x['extensions']);
                     if (self::$_debug) {
                         self::_addToDump("\t" . '$routes->extensions(' . self::_arrToStr($x['extensions']) . ');');
                     }
                 }
                 $x = self::_createPassParams($x);
                 $opts = [];
                 foreach ($x as $k => $item) {
                     if (!in_array($k, $exclude)) {
                         $opts[$k] = $item;
                     }
                 }
                 $thirdParam = self::_buildThirdParam($key, $x);
                 /* @var \Cake\Routing\Router $routes */
                 $routes->connect('/' . self::_varsToString($x['path']), $opts, $thirdParam);
                 // Debugging
                 if (self::$_debug) {
                     self::_addToDump("\t" . '$routes->connect(\'' . self::_varsToString($x['path']) . '\', ' . self::_arrToStr($opts) . ', ' . self::_arrToStr($thirdParam) . ');');
                 }
             }
         }
         if (isset($route['config']) && isset($route['config']['fallbacks'])) {
             $fallbacks = $route['config']['fallbacks'];
         } else {
             $fallbacks = 'DashedRoute';
         }
         /* @var \Cake\Routing\RouteBuilder $routes */
         $routes->fallbacks($fallbacks);
         // Debugging
         if (self::$_debug) {
             self::_addToDump("\t" . '$routes->fallbacks(\'' . $fallbacks . '\');');
         }
     });
     // Debugging
     if (self::$_debug) {
         self::_addToDump('});' . "\n");
     }
 }
Пример #9
0
 /**
  * New route
  *
  * @param $name
  * @param $route
  */
 private function _newRoute($name, $route)
 {
     $method = 'scope';
     $path = '/';
     $options = [];
     if (isset($route['config'])) {
         if (isset($route['config']['plugin']) && Plugin::getInstance()->isLoaded($route['config']['plugin'])) {
             $method = 'plugin';
             $path = $route['config']['plugin'];
             $options = ['path' => $route['path']];
         }
     }
     // Set default route class
     if (isset($route['config']['default_route_class'])) {
         if (in_array($route['config']['default_route_class'], ['Route', 'InflectedRoute', 'DashedRoute'])) {
             Router::defaultRouteClass($route['config']['default_route_class']);
             $this->_addToDump("\\Cake\\Routing\\Router::defaultRouteClass('" . $route['config']['default_route_class'] . "');\n");
         }
     }
     // Debugging
     if ($this->_debug) {
         $this->_addToDump("\\Cake\\Routing\\Router::{$method}('{$path}', " . $this->_arrToStr($options) . ", function (" . '$routes' . ") {");
     }
     Router::$method($path, $options, function ($routes) use($route, $name, $method) {
         $exclude = ['validate', 'routes', 'extensions', 'default_route_class', 'path'];
         if (isset($route['config'])) {
             if (isset($route['config']['extensions']) && is_array($route['config']['extensions'])) {
                 /* @var \Cake\Routing\Router $routes */
                 $routes->extensions($route['config']['extensions']);
                 if ($this->_debug) {
                     $this->_addToDump("\t" . '$routes->extensions(' . $this->_arrToStr($route['config']['extensions']) . ');');
                 }
             }
             if (isset($route['config']['controller'])) {
                 $opts = [];
                 foreach ($route['config'] as $key => $item) {
                     if (!in_array($key, $exclude)) {
                         if (is_array($item) && $key === 'pass') {
                             foreach ($item as $i => $y) {
                                 $opts[$i] = $y;
                             }
                         } else {
                             $opts[$key] = $item;
                         }
                     }
                 }
                 $route = $this->_createPassParams($route);
                 $thirdParam = $this->_buildThirdParam($name, $route);
                 $path = $method == 'scope' ? $route['path'] : '/';
                 /* @var \Cake\Routing\Router $routes */
                 $routes->connect($path, $opts, $thirdParam);
                 // Debugging
                 if ($this->_debug) {
                     $this->_addToDump("\t" . '$routes->connect(\'' . $path . '\', ' . $this->_arrToStr($opts) . ', ' . $this->_arrToStr($thirdParam) . ');');
                 }
             }
             if (isset($route['config']['routes'])) {
                 foreach ($route['config']['routes'] as $key => $x) {
                     if (isset($x['config'])) {
                         if (isset($x['config']['extensions']) && is_array($x['config']['extensions'])) {
                             /* @var \Cake\Routing\Router $routes */
                             $routes->extensions($x['config']['extensions']);
                             if ($this->_debug) {
                                 $this->_addToDump("\t" . '$routes->extensions(' . $this->_arrToStr($x['config']['extensions']) . ');');
                             }
                         }
                         $opts = [];
                         foreach ($x['config'] as $k => $item) {
                             if (!in_array($k, $exclude)) {
                                 if (is_array($item) && $k === 'pass') {
                                     foreach ($item as $i => $y) {
                                         $opts[$i] = $y;
                                     }
                                 } else {
                                     $opts[$k] = $item;
                                 }
                             }
                         }
                         $x = self::_createPassParams($x);
                         $thirdParam = $this->_buildThirdParam($key, $x);
                         /* @var \Cake\Routing\Router $routes */
                         $routes->connect('/' . $this->_varsToString($x['path']), $opts, $thirdParam);
                         // Debugging
                         if ($this->_debug) {
                             $this->_addToDump("\t" . '$routes->connect(\'' . $this->_varsToString($x['path']) . '\', ' . $this->_arrToStr($opts) . ', ' . $this->_arrToStr($thirdParam) . ');');
                         }
                     }
                 }
             }
         }
         $this->_createFallbacks($routes, $route);
     });
     // Debugging
     if ($this->_debug) {
         $this->_addToDump('});' . "\n");
     }
 }
Пример #10
0
<?php

use Cake\Routing\RouteBuilder;
use Cake\Routing\Router;
Router::plugin('ImagePresenter', ['path' => '/image-presenter'], function (RouteBuilder $routes) {
    $routes->fallbacks(Router::defaultRouteClass());
});