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


PHP Router::getNamedExpressions方法代码示例

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


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

示例1: testUrlParsing

 /**
  * testUrlParsing method
  *
  * @return void
  */
 public function testUrlParsing()
 {
     extract(Router::getNamedExpressions());
     Router::connect('/posts/:value/:somevalue/:othervalue/*', array('controller' => 'posts', 'action' => 'view'), array('value', 'somevalue', 'othervalue'));
     $result = Router::parse('/posts/2007/08/01/title-of-post-here');
     $expected = array('value' => '2007', 'somevalue' => '08', 'othervalue' => '01', 'controller' => 'posts', 'action' => 'view', 'plugin' => null, 'pass' => array('0' => 'title-of-post-here'));
     $this->assertEquals($expected, $result);
     Router::reload();
     Router::connect('/posts/:year/:month/:day/*', array('controller' => 'posts', 'action' => 'view'), array('year' => $Year, 'month' => $Month, 'day' => $Day));
     $result = Router::parse('/posts/2007/08/01/title-of-post-here');
     $expected = array('year' => '2007', 'month' => '08', 'day' => '01', 'controller' => 'posts', 'action' => 'view', 'plugin' => null, 'pass' => array('0' => 'title-of-post-here'));
     $this->assertEquals($expected, $result);
     Router::reload();
     Router::connect('/posts/:day/:year/:month/*', array('controller' => 'posts', 'action' => 'view'), array('year' => $Year, 'month' => $Month, 'day' => $Day));
     $result = Router::parse('/posts/01/2007/08/title-of-post-here');
     $expected = array('day' => '01', 'year' => '2007', 'month' => '08', 'controller' => 'posts', 'action' => 'view', 'plugin' => null, 'pass' => array('0' => 'title-of-post-here'));
     $this->assertEquals($expected, $result);
     Router::reload();
     Router::connect('/posts/:month/:day/:year/*', array('controller' => 'posts', 'action' => 'view'), array('year' => $Year, 'month' => $Month, 'day' => $Day));
     $result = Router::parse('/posts/08/01/2007/title-of-post-here');
     $expected = array('month' => '08', 'day' => '01', 'year' => '2007', 'controller' => 'posts', 'action' => 'view', 'plugin' => null, 'pass' => array('0' => 'title-of-post-here'));
     $this->assertEquals($expected, $result);
     Router::reload();
     Router::connect('/posts/:year/:month/:day/*', array('controller' => 'posts', 'action' => 'view'));
     $result = Router::parse('/posts/2007/08/01/title-of-post-here');
     $expected = array('year' => '2007', 'month' => '08', 'day' => '01', 'controller' => 'posts', 'action' => 'view', 'plugin' => null, 'pass' => array('0' => 'title-of-post-here'));
     $this->assertEquals($expected, $result);
     Router::reload();
     require CAKE . 'Config/routes.php';
     $result = Router::parse('/pages/display/home');
     $expected = array('plugin' => null, 'pass' => array('home'), 'controller' => 'pages', 'action' => 'display');
     $this->assertEquals($expected, $result);
     $result = Router::parse('pages/display/home/');
     $this->assertEquals($expected, $result);
     $result = Router::parse('pages/display/home');
     $this->assertEquals($expected, $result);
     Router::reload();
     Router::connect('/page/*', array('controller' => 'test'));
     $result = Router::parse('/page/my-page');
     $expected = array('pass' => array('my-page'), 'plugin' => null, 'controller' => 'test', 'action' => 'index');
     $this->assertEquals($expected, $result);
     Router::reload();
     Router::connect('/:language/contact', array('language' => 'eng', 'plugin' => 'contact', 'controller' => 'contact', 'action' => 'index'), array('language' => '[a-z]{3}'));
     $result = Router::parse('/eng/contact');
     $expected = array('pass' => [], 'language' => 'eng', 'plugin' => 'contact', 'controller' => 'contact', 'action' => 'index');
     $this->assertEquals($expected, $result);
     Router::reload();
     Router::connect('/forestillinger/:month/:year/*', array('plugin' => 'shows', 'controller' => 'shows', 'action' => 'calendar'), array('month' => '0[1-9]|1[012]', 'year' => '[12][0-9]{3}'));
     $result = Router::parse('/forestillinger/10/2007/min-forestilling');
     $expected = array('pass' => array('min-forestilling'), 'plugin' => 'shows', 'controller' => 'shows', 'action' => 'calendar', 'year' => 2007, 'month' => 10);
     $this->assertEquals($expected, $result);
     Router::reload();
     Router::connect('/:controller/:action/*');
     Router::connect('/', array('plugin' => 'pages', 'controller' => 'pages', 'action' => 'display'));
     $result = Router::parse('/');
     $expected = array('pass' => [], 'controller' => 'pages', 'action' => 'display', 'plugin' => 'pages');
     $this->assertEquals($expected, $result);
     $result = Router::parse('/posts/edit/0');
     $expected = array('pass' => array(0), 'controller' => 'posts', 'action' => 'edit', 'plugin' => null);
     $this->assertEquals($expected, $result);
     Router::reload();
     Router::connect('/posts/:id::url_title', array('controller' => 'posts', 'action' => 'view'), array('pass' => array('id', 'url_title'), 'id' => '[\\d]+'));
     $result = Router::parse('/posts/5:sample-post-title');
     $expected = array('pass' => array('5', 'sample-post-title'), 'id' => 5, 'url_title' => 'sample-post-title', 'plugin' => null, 'controller' => 'posts', 'action' => 'view');
     $this->assertEquals($expected, $result);
     Router::reload();
     Router::connect('/posts/:id::url_title/*', array('controller' => 'posts', 'action' => 'view'), array('pass' => array('id', 'url_title'), 'id' => '[\\d]+'));
     $result = Router::parse('/posts/5:sample-post-title/other/params/4');
     $expected = array('pass' => array('5', 'sample-post-title', 'other', 'params', '4'), 'id' => 5, 'url_title' => 'sample-post-title', 'plugin' => null, 'controller' => 'posts', 'action' => 'view');
     $this->assertEquals($expected, $result);
     Router::reload();
     Router::connect('/posts/view/*', array('controller' => 'posts', 'action' => 'view'));
     $result = Router::parse('/posts/view/10?id=123&tab=abc');
     $expected = array('pass' => array(10), 'plugin' => null, 'controller' => 'posts', 'action' => 'view', '?' => array('id' => '123', 'tab' => 'abc'));
     $this->assertEquals($expected, $result);
     Router::reload();
     Router::connect('/posts/:url_title-(uuid::id)', array('controller' => 'posts', 'action' => 'view'), array('pass' => array('id', 'url_title'), 'id' => $UUID));
     $result = Router::parse('/posts/sample-post-title-(uuid:47fc97a9-019c-41d1-a058-1fa3cbdd56cb)');
     $expected = array('pass' => array('47fc97a9-019c-41d1-a058-1fa3cbdd56cb', 'sample-post-title'), 'id' => '47fc97a9-019c-41d1-a058-1fa3cbdd56cb', 'url_title' => 'sample-post-title', 'plugin' => null, 'controller' => 'posts', 'action' => 'view');
     $this->assertEquals($expected, $result);
     Router::reload();
     Router::connect('/posts/view/*', array('controller' => 'posts', 'action' => 'view'));
     $result = Router::parse('/posts/view/foo:bar/routing:fun');
     $expected = array('pass' => array('foo:bar', 'routing:fun'), 'plugin' => null, 'controller' => 'posts', 'action' => 'view');
     $this->assertEquals($expected, $result);
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:91,代码来源:RouterTest.php


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