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


PHP CakeRoute::compile方法代码示例

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


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

示例1: testRouteCompilingWithParamPatterns

 /**
  * test compiling routes with keys that have patterns
  *
  * @return void
  **/
 function testRouteCompilingWithParamPatterns()
 {
     extract(Router::getNamedExpressions());
     $route = new CakeRoute('/:controller/:action/:id', array(), array('id' => $ID));
     $result = $route->compile();
     $this->assertPattern($result, '/posts/edit/1');
     $this->assertPattern($result, '/posts/view/518098');
     $this->assertNoPattern($result, '/posts/edit/name-of-post');
     $this->assertNoPattern($result, '/posts/edit/4/other:param');
     $this->assertEqual($route->keys, array('controller', 'action', 'id'));
     $route =& new CakeRoute('/:lang/:controller/:action/:id', array('controller' => 'testing4'), array('id' => $ID, 'lang' => '[a-z]{3}'));
     $result = $route->compile();
     $this->assertPattern($result, '/eng/posts/edit/1');
     $this->assertPattern($result, '/cze/articles/view/1');
     $this->assertNoPattern($result, '/language/articles/view/2');
     $this->assertNoPattern($result, '/eng/articles/view/name-of-article');
     $this->assertEqual($route->keys, array('lang', 'controller', 'action', 'id'));
     foreach (array(':', '@', ';', '$', '-') as $delim) {
         $route =& new CakeRoute('/posts/:id' . $delim . ':title');
         $result = $route->compile();
         $this->assertPattern($result, '/posts/1' . $delim . 'name-of-article');
         $this->assertPattern($result, '/posts/13244' . $delim . 'name-of_Article[]');
         $this->assertNoPattern($result, '/posts/11!nameofarticle');
         $this->assertNoPattern($result, '/posts/11');
         $this->assertEqual($route->keys, array('id', 'title'));
     }
     $route =& new CakeRoute('/posts/:id::title/:year', array('controller' => 'posts', 'action' => 'view'), array('id' => $ID, 'year' => $Year, 'title' => '[a-z-_]+'));
     $result = $route->compile();
     $this->assertPattern($result, '/posts/1:name-of-article/2009/');
     $this->assertPattern($result, '/posts/13244:name-of-article/1999');
     $this->assertNoPattern($result, '/posts/hey_now:nameofarticle');
     $this->assertNoPattern($result, '/posts/:nameofarticle/2009');
     $this->assertNoPattern($result, '/posts/:nameofarticle/01');
     $this->assertEqual($route->keys, array('id', 'title', 'year'));
     $route =& new CakeRoute('/posts/:url_title-(uuid::id)', array('controller' => 'posts', 'action' => 'view'), array('pass' => array('id', 'url_title'), 'id' => $ID));
     $result = $route->compile();
     $this->assertPattern($result, '/posts/some_title_for_article-(uuid:12534)/');
     $this->assertPattern($result, '/posts/some_title_for_article-(uuid:12534)');
     $this->assertNoPattern($result, '/posts/');
     $this->assertNoPattern($result, '/posts/nameofarticle');
     $this->assertNoPattern($result, '/posts/nameofarticle-12347');
     $this->assertEqual($route->keys, array('url_title', 'id'));
 }
开发者ID:aqua777,项目名称:rackdoc,代码行数:48,代码来源:router.test.php

示例2: testParse

 /**
  * test the parse method of CakeRoute.
  *
  * @return void
  */
 public function testParse()
 {
     $route = new CakeRoute('/:controller/:action/:id', array('controller' => 'testing4', 'id' => null), array('id' => Router::ID));
     $route->compile();
     $result = $route->parse('/posts/view/1');
     $this->assertEquals('posts', $result['controller']);
     $this->assertEquals('view', $result['action']);
     $this->assertEquals('1', $result['id']);
     $route = new Cakeroute('/admin/:controller', array('prefix' => 'admin', 'admin' => 1, 'action' => 'index'));
     $route->compile();
     $result = $route->parse('/admin/');
     $this->assertFalse($result);
     $result = $route->parse('/admin/posts');
     $this->assertEquals('posts', $result['controller']);
     $this->assertEquals('index', $result['action']);
 }
开发者ID:pritten,项目名称:SmartCitizen.me,代码行数:21,代码来源:CakeRouteTest.php

示例3: testParse

 /**
  * test the parse method of CakeRoute.
  *
  * @return void
  */
 function testParse()
 {
     extract(Router::getNamedExpressions());
     $route = new CakeRoute('/:controller/:action/:id', array('controller' => 'testing4', 'id' => null), array('id' => $ID));
     $route->compile();
     $result = $route->parse('/posts/view/1');
     $this->assertEqual($result['controller'], 'posts');
     $this->assertEqual($result['action'], 'view');
     $this->assertEqual($result['id'], '1');
 }
开发者ID:robksawyer,项目名称:cakephp2x,代码行数:15,代码来源:router.test.php


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