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