本文整理汇总了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'));
}
示例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']);
}
示例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');
}