當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。