当前位置: 首页>>代码示例>>PHP>>正文


PHP Router::mapResources方法代码示例

本文整理汇总了PHP中Cake\Routing\Router::mapResources方法的典型用法代码示例。如果您正苦于以下问题:PHP Router::mapResources方法的具体用法?PHP Router::mapResources怎么用?PHP Router::mapResources使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cake\Routing\Router的用法示例。


在下文中一共展示了Router::mapResources方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testHttpMethodOverrides

 /**
  * testHttpMethodOverrides method
  *
  * @return void
  */
 public function testHttpMethodOverrides()
 {
     Router::reload();
     Router::mapResources('Posts');
     $dispatcher = new Dispatcher();
     $request = new Request(['url' => '/posts', 'environment' => ['REQUEST_METHOD' => 'POST']]);
     $event = new Event(__CLASS__, $dispatcher, array('request' => $request));
     $dispatcher->parseParams($event);
     $expected = array('pass' => [], 'plugin' => null, 'controller' => 'posts', 'action' => 'add', '[method]' => 'POST');
     foreach ($expected as $key => $value) {
         $this->assertEquals($value, $request[$key], 'Value mismatch for ' . $key . ' %s');
     }
     $request = new Request(['url' => '/posts/5', 'environment' => ['REQUEST_METHOD' => 'GET', 'HTTP_X_HTTP_METHOD_OVERRIDE' => 'PUT']]);
     $event = new Event(__CLASS__, $dispatcher, array('request' => $request));
     $dispatcher->parseParams($event);
     $expected = array('pass' => array('5'), 'id' => '5', 'plugin' => null, 'controller' => 'posts', 'action' => 'edit', '[method]' => 'PUT');
     foreach ($expected as $key => $value) {
         $this->assertEquals($value, $request[$key], 'Value mismatch for ' . $key . ' %s');
     }
     $request = new Request(['url' => '/posts/5', 'environment' => ['REQUEST_METHOD' => 'GET']]);
     $event = new Event(__CLASS__, $dispatcher, array('request' => $request));
     $dispatcher->parseParams($event);
     $expected = array('pass' => array('5'), 'id' => '5', 'plugin' => null, 'controller' => 'posts', 'action' => 'view', '[method]' => 'GET');
     foreach ($expected as $key => $value) {
         $this->assertEquals($value, $request[$key], 'Value mismatch for ' . $key . ' %s');
     }
     $request = new Request(['url' => '/posts/5', 'post' => array('_method' => 'PUT')]);
     $event = new Event(__CLASS__, $dispatcher, array('request' => $request));
     $dispatcher->parseParams($event);
     $expected = array('pass' => array('5'), 'id' => '5', 'plugin' => null, 'controller' => 'posts', 'action' => 'edit', '[method]' => 'PUT');
     foreach ($expected as $key => $value) {
         $this->assertEquals($value, $request[$key], 'Value mismatch for ' . $key . ' %s');
     }
     $request = new Request(array('url' => '/posts', 'post' => array('_method' => 'POST', 'Post' => array('title' => 'New Post'), 'extra' => 'data')));
     $event = new Event(__CLASS__, $dispatcher, array('request' => $request));
     $dispatcher->parseParams($event);
     $expected = array('pass' => [], 'plugin' => null, 'controller' => 'posts', 'action' => 'add', '[method]' => 'POST', 'data' => array('extra' => 'data', 'Post' => array('title' => 'New Post')));
     foreach ($expected as $key => $value) {
         $this->assertEquals($value, $request[$key], 'Value mismatch for ' . $key . ' %s');
     }
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:46,代码来源:DispatcherTest.php

示例2: testGenerateUrlResourceRoute

 /**
  * testGenerateUrlResourceRoute method
  *
  * @return void
  */
 public function testGenerateUrlResourceRoute()
 {
     Router::mapResources('Posts');
     $result = Router::url(['controller' => 'posts', 'action' => 'index', '[method]' => 'GET']);
     $expected = '/posts';
     $this->assertEquals($expected, $result);
     $result = Router::url(['controller' => 'posts', 'action' => 'view', '[method]' => 'GET', 'id' => 10]);
     $expected = '/posts/10';
     $this->assertEquals($expected, $result);
     $result = Router::url(['controller' => 'posts', 'action' => 'add', '[method]' => 'POST']);
     $expected = '/posts';
     $this->assertEquals($expected, $result);
     $result = Router::url(['controller' => 'posts', 'action' => 'edit', '[method]' => 'PUT', 'id' => 10]);
     $expected = '/posts/10';
     $this->assertEquals($expected, $result);
     $result = Router::url(['controller' => 'posts', 'action' => 'delete', '[method]' => 'DELETE', 'id' => 10]);
     $expected = '/posts/10';
     $this->assertEquals($expected, $result);
     $result = Router::url(['controller' => 'posts', 'action' => 'edit', '[method]' => 'POST', 'id' => 10]);
     $expected = '/posts/10';
     $this->assertEquals($expected, $result);
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:27,代码来源:RouterTest.php

示例3:

     * 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();
开发者ID:BharadhwajGummadi,项目名称:library,代码行数:31,代码来源:routes.php

示例4: 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('DashedRoute');
Router::mapResources('jobs');
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']);
    /**
     * Connect catchall routes for all controllers.
     *
     * Using the argument `DashedRoute`, the `fallbacks` method is a shortcut for
开发者ID:EisenerGustav,项目名称:JobsApi,代码行数:31,代码来源:routes.php


注:本文中的Cake\Routing\Router::mapResources方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。