本文整理汇总了PHP中Cake\Routing\Router::prefix方法的典型用法代码示例。如果您正苦于以下问题:PHP Router::prefix方法的具体用法?PHP Router::prefix怎么用?PHP Router::prefix使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Routing\Router
的用法示例。
在下文中一共展示了Router::prefix方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
/**
* reset environment.
*
* @return void
*/
public function setUp()
{
parent::setUp();
Configure::write('App.namespace', 'TestApp');
Plugin::load(array('TestPlugin', 'TestPluginTwo'));
$this->Case = $this->getMockForAbstractClass('Cake\\TestSuite\\ControllerTestCase');
$this->Case->loadRoutes = false;
DispatcherFactory::add('Routing');
DispatcherFactory::add('ControllerFactory');
Router::scope('/', function ($routes) {
$routes->fallbacks();
});
Router::prefix('admin', function ($routes) {
$routes->plugin('TestPlugin', function ($routes) {
$routes->fallbacks();
});
$routes->fallbacks();
});
Router::plugin('TestPlugin', function ($routes) {
$routes->fallbacks();
});
Router::plugin('TestPluginTwo', function ($routes) {
$routes->fallbacks();
});
TableRegistry::clear();
}
示例2: testBuildResetWithPlugin
/**
* @return void
*/
public function testBuildResetWithPlugin()
{
Router::connect('/:controller/:action/*');
$result = $this->Url->buildReset(['controller' => 'foobar', 'action' => 'test']);
$expected = '/foobar/test';
$this->assertSame($expected, $result);
$this->Url->request->here = '/admin/foo/bar/baz/test';
$this->Url->request->params['prefix'] = 'admin';
$this->Url->request->params['plugin'] = 'Foo';
Router::reload();
Router::connect('/:controller/:action/*');
Router::plugin('Foo', function ($routes) {
$routes->fallbacks();
});
Router::prefix('admin', function ($routes) {
$routes->plugin('Foo', function ($routes) {
$routes->fallbacks();
});
});
Plugin::routes();
Router::pushRequest($this->Url->request);
$result = $this->Url->build(['controller' => 'bar', 'action' => 'baz', 'x']);
$expected = '/admin/foo/bar/baz/x';
$this->assertSame($expected, $result);
$result = $this->Url->buildReset(['controller' => 'bar', 'action' => 'baz', 'x']);
$expected = '/bar/baz/x';
$this->assertSame($expected, $result);
}
示例3: testResetLink
/**
* Tests
*
* @return void
*/
public function testResetLink()
{
Router::connect('/:controller/:action/*');
$result = $this->Html->resetLink('Foo', ['controller' => 'foobar', 'action' => 'test']);
$expected = '<a href="/foobar/test">Foo</a>';
$this->assertEquals($expected, $result);
$this->Html->request->here = '/admin/foobar/test';
$this->Html->request->params['admin'] = true;
$this->Html->request->params['prefix'] = 'admin';
Router::reload();
Router::connect('/:controller/:action/*');
Router::prefix('admin', function ($routes) {
$routes->connect('/:controller/:action/*');
});
$result = $this->Html->link('Foo', ['prefix' => 'admin', 'controller' => 'foobar', 'action' => 'test']);
$expected = '<a href="/admin/foobar/test">Foo</a>';
$this->assertEquals($expected, $result);
$result = $this->Html->link('Foo', ['controller' => 'foobar', 'action' => 'test']);
$expected = '<a href="/admin/foobar/test">Foo</a>';
//debug($result);
//$this->assertEquals($expected, $result);
$result = $this->Html->resetLink('Foo', ['controller' => 'foobar', 'action' => 'test']);
$expected = '<a href="/foobar/test">Foo</a>';
$this->assertEquals($expected, $result);
}
示例4: function
* 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) {
// All routes here will be prefixed with `/admin`
// And have the prefix => admin route element added
$routes->redirect('/users/login', BASE_URL . '/users/login', ['status' => 302]);
$routes->redirect('/users/logout', BASE_URL . '/users/logout', ['status' => 302]);
$routes->fallbacks(DashedRoute::class);
});
Plugin::routes();
示例5: function
/**
* Adding routes for the admin-prefix and CakeManager-Plugin
*/
Router::prefix('admin', function ($routes) {
$routes->plugin('CakeManager', ['path' => '/manager'], function ($routes) {
$routes->fallbacks('InflectedRoute');
});
$routes->fallbacks('InflectedRoute');
});
/**
* Adding routes for the api-prefix and CakeManager-Plugin
*/
Router::prefix('api', function ($routes) {
$routes->plugin('CakeManager', ['path' => '/'], function ($routes) {
$routes->extensions(['json']);
$routes->resources('Roles');
$routes->resources('Users');
$routes->fallbacks('InflectedRoute');
});
});
/*
* Adding default routes for the CakeManager
*/
Router::plugin('CakeManager', ['path' => '/'], function ($routes) {
$routes->fallbacks('InflectedRoute');
});
/**
* Default routes for usersController from the CakeManager
*
* Previous:
* manager/users/request
*
示例6: function
*
*/
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' => 'Home', 'action' => 'index']);
/**
* ...and connect the rest of 'Pages' controller's URLs.
*/
$routes->connect('/pages/*', ['controller' => 'Home', 'action' => 'index']);
Router::prefix('admin', function ($routes) {
$routes->connect('/admin/*', ['controller' => 'Users', 'action' => 'dashboard']);
$routes->fallbacks('InflectedRoute');
});
/**
* 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
示例7: function
*
* 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');
});
Router::prefix('admin', function ($routes) {
$routes->connect('/', ['controller' => 'Dashboard', 'action' => 'index']);
$routes->connect('/login', ['controller' => 'Users', 'action' => 'login']);
$routes->connect('/logout', ['controller' => 'Users', 'action' => 'logout']);
//Password recovery
$routes->connect('/lost-password', ['controller' => 'Users', 'action' => 'lostPassword']);
$routes->connect('/reset-password/:token/:email', ['controller' => 'Users', 'action' => 'resetPassword'], ['token' => '[a-z0-9]+', 'email' => '^[A-Za-z0-9._%+-]+@([A-Za-z0-9-]+\\.)+([A-Za-z0-9]{2,4}|museum)$', 'pass' => ['token', 'email']]);
//Register account
$routes->connect('/register', ['controller' => 'Users', 'action' => 'register']);
$routes->connect('/active-account/:token/:email', ['controller' => 'Users', 'action' => 'activeAccount'], ['token' => '[a-z0-9]+', 'email' => '^[A-Za-z0-9._%+-]+@([A-Za-z0-9-]+\\.)+([A-Za-z0-9]{2,4}|museum)$', 'pass' => ['token', 'email']]);
$routes->connect('/:controller', ['action' => 'index']);
$routes->connect('/:controller/:action/*', []);
$routes->fallbacks('DashedRoute');
});
/**
* Load all plugin routes. See the Plugin documentation on
* how to customize the loading of plugin routes.
*/
Plugin::routes();
示例8: function
<?php
use Cake\Routing\Router;
Router::prefix('admin', function ($routes) {
$routes->connect('/feedbacks', ['plugin' => 'AkkaFeedback', 'controller' => 'Feedbacks', 'action' => 'index'], ['routeClass' => 'DashedRoute']);
$routes->connect('/feedbacks/:action/*', ['plugin' => 'AkkaFeedback', 'controller' => 'Feedbacks'], ['routeClass' => 'DashedRoute']);
$routes->plugin('AkkaFeedback', function ($routes) {
$routes->connect('/:controller', ['action' => 'index'], ['routeClass' => 'DashedRoute']);
$routes->connect('/:controller/:action/*', [], ['routeClass' => 'DashedRoute']);
});
});
Router::plugin('AkkaFeedback', ['path' => '/akka-feedback'], function ($routes) {
$routes->fallbacks('DashedRoute');
});
示例9: function
*
* 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');
});
Router::prefix('admin', function ($routes) {
// All routes here will be prefixed with `/admin`
// And have the prefix => admin route element added.
$routes->fallbacks('DashedRoute');
});
Router::prefix('mianst', function ($routes) {
// All routes here will be prefixed with `/admin`
// And have the prefix => admin route element added.
$routes->fallbacks('DashedRoute');
});
/**
* Load all plugin routes. See the Plugin documentation on
* how to customize the loading of plugin routes.
*/
Plugin::routes();
示例10: function
* `$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');
});
Router::prefix('admin', function ($routes) {
$routes->connect('/', ['controller' => 'Reservations', 'action' => 'index', 'home']);
$routes->fallbacks('DashedRoute');
});
Router::prefix('hotel', function ($routes) {
$routes->connect('/', ['controller' => 'Reservations', 'action' => 'index', 'home']);
$routes->fallbacks('DashedRoute');
});
Router::prefix('restau', function ($routes) {
$routes->connect('/', ['controller' => 'Orders', 'action' => 'index', 'home']);
$routes->fallbacks('DashedRoute');
});
/**
* Load all plugin routes. See the Plugin documentation on
* how to customize the loading of plugin routes.
*/
Plugin::routes();
示例11: function
*
*/
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']);
/**
* ...and connect the rest of 'Pages' controller's URLs.
*/
$routes->connect('/pages/*', ['controller' => 'Pages', 'action' => 'display']);
Router::prefix('Admin', function ($routes) {
$routes->fallbacks('InflectedRoute');
});
/**
* Connect catchall routes for all controllers.
*
* Using the argument `InflectedRoute`, the `fallbacks` method is a shortcut for
* `$routes->connect('/:controller', ['action' => 'index'], ['routeClass' => 'InflectedRoute']);`
* `$routes->connect('/:controller/:action/*', [], ['routeClass' => 'InflectedRoute']);`
*
* 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
示例12: function
* 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');
});
//Router::scope('/', function ($routes) {
Router::prefix('api', function ($routes) {
/**
* we are add 'api' as a prefix for all url
*/
$routes->extensions(['json', 'xml']);
$routes->resources('Users');
$routes->resources('Hierarchies');
$routes->resources('Dispositions');
$routes->fallbacks('InflectedRoute');
});
/**
* Load all plugin routes. See the Plugin documentation on
* how to customize the loading of plugin routes.
*/
Plugin::routes();
示例13: function
/**
* CakeManager (http://cakemanager.org)
* Copyright (c) http://cakemanager.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) http://cakemanager.org
* @link http://cakemanager.org CakeManager Project
* @since 1.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
use Cake\Routing\Router;
Router::prefix('admin', function ($routes) {
$routes->connect('/', ['plugin' => 'CakeAdmin', 'controller' => 'Users', 'action' => 'login']);
$routes->fallbacks('InflectedRoute');
});
Router::plugin('CakeAdmin', ['path' => '/'], function ($routes) {
$routes->prefix('admin', function ($routes) {
$routes->connect('/login', ['controller' => 'Users', 'action' => 'login']);
$routes->connect('/logout', ['controller' => 'Users', 'action' => 'logout']);
$routes->connect('/posttypes/:type/:action/*', ['controller' => 'PostTypes'], ['pass' => ['type']]);
$routes->connect('/', ['controller' => 'Users', 'action' => 'login']);
$routes->connect('/users/:action/*', ['controller' => 'Users']);
$routes->connect('/dashboard', ['controller' => 'Dashboard']);
$routes->connect('/notifications/**', ['controller' => 'Notifications']);
$routes->connect('/settings/**', ['controller' => 'Settings']);
$routes->fallbacks('InflectedRoute');
});
});
示例14: function
* 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.
*/
Router::prefix('api', function ($routes) {
$routes->extensions(['json', 'xml']);
//$routes->connect('/:controller');
$routes->resources('Requirements', ['id' => '[0-9A-Za-z]+']);
});
//$routes->fallbacks('DashedRoute');
//});
/**
* Load all plugin routes. See the Plugin documentation on
* how to customize the loading of plugin routes.
*/
Plugin::routes();
/*$routes = Router::routes();
echo('<pre>'); // Readable output
var_dump($routes);
echo('</pre>');*/
示例15: function
/*
* Routes amenant a l'inscription à un évènement d'un nouvel utilisateur
*/
$routes->connect('/evenement/:slug.:id', ['controller' => 'Events', 'action' => 'inscription'], ['_name' => 'form-inscription', 'pass' => ['id', 'slug'], 'id' => '[0-9]+']);
/**
* 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');
});
Router::prefix('Admin', function ($routes) {
$routes->connect('/', ['controller' => 'Pages', 'action' => 'dashboard', 'prefix' => 'admin'], ['_name' => 'Dashboard']);
$routes->fallbacks('DashedRoute');
});
/**
* Load all plugin routes. See the Plugin documentation on
* how to customize the loading of plugin routes.
*/
Plugin::routes();