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


PHP Router::prefixes方法代码示例

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


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

示例1: _setPrefixMappings

 /**
  * sets the crud mappings for prefix routes.
  *
  * @return void
  */
 protected function _setPrefixMappings()
 {
     $crud = array('create', 'read', 'update', 'delete');
     $map = array_combine($crud, $crud);
     $prefixes = Router::prefixes();
     if (!empty($prefixes)) {
         foreach ($prefixes as $prefix) {
             $map = array_merge($map, array($prefix . '_index' => 'read', $prefix . '_add' => 'create', $prefix . '_edit' => 'update', $prefix . '_view' => 'read', $prefix . '_remove' => 'delete', $prefix . '_create' => 'create', $prefix . '_read' => 'read', $prefix . '_update' => 'update', $prefix . '_delete' => 'delete'));
         }
     }
     $this->mapActions($map);
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:17,代码来源:CrudAuthorize.php

示例2: testParsingWithLiteralPrefixes

 /**
  * testParsingWithLiteralPrefixes method
  *
  * @return void
  */
 public function testParsingWithLiteralPrefixes()
 {
     Configure::write('Routing.prefixes', []);
     Router::reload();
     $adminParams = array('prefix' => 'admin');
     Router::connect('/admin/:controller', $adminParams);
     Router::connect('/admin/:controller/:action', $adminParams);
     Router::connect('/admin/:controller/:action/*', $adminParams);
     $request = new Request();
     Router::setRequestInfo($request->addParams(array('plugin' => null, 'controller' => 'controller', 'action' => 'index'))->addPaths(array('base' => '/base', 'here' => '/', 'webroot' => '/base/')));
     $result = Router::parse('/admin/posts/');
     $expected = array('pass' => [], 'prefix' => 'admin', 'plugin' => null, 'controller' => 'posts', 'action' => 'index');
     $this->assertEquals($expected, $result);
     $result = Router::parse('/admin/posts');
     $this->assertEquals($expected, $result);
     $result = Router::url(array('prefix' => 'admin', 'controller' => 'posts'));
     $expected = '/base/admin/posts';
     $this->assertEquals($expected, $result);
     $result = Router::prefixes();
     $expected = [];
     $this->assertEquals($expected, $result);
     Router::reload();
     $prefixParams = array('prefix' => 'members');
     Router::connect('/members/:controller', $prefixParams);
     Router::connect('/members/:controller/:action', $prefixParams);
     Router::connect('/members/:controller/:action/*', $prefixParams);
     $request = new Request();
     Router::setRequestInfo($request->addParams(array('plugin' => null, 'controller' => 'controller', 'action' => 'index'))->addPaths(array('base' => '/base', 'here' => '/', 'webroot' => '/')));
     $result = Router::parse('/members/posts/index');
     $expected = array('pass' => [], 'prefix' => 'members', 'plugin' => null, 'controller' => 'posts', 'action' => 'index');
     $this->assertEquals($expected, $result);
     $result = Router::url(array('prefix' => 'members', 'controller' => 'users', 'action' => 'add'));
     $expected = '/base/members/users/add';
     $this->assertEquals($expected, $result);
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:40,代码来源:RouterTest.php

示例3: implode

 * - `/:prefix/:controller/:action/*`
 *
 * If plugins are found in your application the following routes are created:
 *
 * - `/:plugin` a plugin shortcut route.
 * - `/:plugin/:controller`
 * - `/:plugin/:controller/:action/*`
 *
 * And lastly the following catch-all routes are connected.
 *
 * - `/:controller'
 * - `/:controller/:action/*'
 *
 * You can disable the connection of default routes by deleting the require inside APP/Config/routes.php.
 */
$prefixes = Router::prefixes();
$prefixPattern = implode('|', $prefixes);
$plugins = Plugin::loaded();
foreach ($plugins as $key => $value) {
    $plugins[$key] = Inflector::underscore($value);
}
$pluginPattern = implode('|', $plugins);
$indexParams = ['action' => 'index'];
$pluginShortMatch = ['routeClass' => 'Cake\\Routing\\Route\\PluginShortRoute', '_name' => '_plugin._controller:index'];
if ($prefixPattern && $pluginPattern) {
    $match = ['prefix' => $prefixPattern, 'plugin' => $pluginPattern];
    Router::connect('/:prefix/:plugin', $indexParams, $match + $pluginShortMatch);
    Router::connect('/:prefix/:plugin/:controller', $indexParams, $match);
    Router::connect('/:prefix/:plugin/:controller/:action/*', [], $match);
}
if ($pluginPattern) {
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:31,代码来源:routes.php

示例4: _isPrivateAction

 /**
  * Check if the request's action is marked as private, with an underscore,
  * or if the request is attempting to directly accessing a prefixed action.
  *
  * @param \ReflectionMethod $method The method to be invoked.
  * @param \Cake\Network\Request $request The request to check.
  * @return bool
  */
 protected function _isPrivateAction(\ReflectionMethod $method, Request $request)
 {
     $privateAction = $method->name[0] === '_' || !$method->isPublic() || !in_array($method->name, $this->methods);
     $prefixes = Router::prefixes();
     if (!$privateAction && !empty($prefixes)) {
         if (empty($request->params['prefix']) && strpos($request->params['action'], '_') > 0) {
             list($prefix) = explode('_', $request->params['action']);
             $privateAction = in_array($prefix, $prefixes);
         }
     }
     return $privateAction;
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:20,代码来源:Controller.php


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