本文整理汇总了PHP中CakeRoute::match方法的典型用法代码示例。如果您正苦于以下问题:PHP CakeRoute::match方法的具体用法?PHP CakeRoute::match怎么用?PHP CakeRoute::match使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CakeRoute
的用法示例。
在下文中一共展示了CakeRoute::match方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: match
/**
* Attempt to match a url array. If the url matches the route parameters + settings, then
* return a generated string url. If the url doesn't match the route parameters false will be returned.
* This method handles the reverse routing or conversion of url arrays into string urls.
*
* @param array $url An array of parameters to check matching with.
* @return mixed Either a string url for the parameters if they match or false.
*/
public function match($url)
{
if (empty($url['lang'])) {
$url['lang'] = Configure::read('Config.language');
}
return parent::match($url);
}
示例2: match
/**
* Reverse route plugin shortcut URLs. If the plugin and controller
* are not the same the match is an auto fail.
*
* @param array $url Array of parameters to convert to a string.
* @return mixed either false or a string URL.
*/
public function match($url) {
if (isset($url['controller']) && isset($url['plugin']) && $url['plugin'] != $url['controller']) {
return false;
}
$this->defaults['controller'] = $url['controller'];
$result = parent::match($url);
unset($this->defaults['controller']);
return $result;
}
示例3: match
public function match($params)
{
$subdomain = isset($params['subdomain']) ? $params['subdomain'] : '';
unset($params['subdomain']);
$path = parent::match($params);
$domain = $this->_getDomain();
if ($subdomain) {
$path = 'http://' . $subdomain . '.' . $domain . $path;
}
return $path;
}
示例4: match
public function match($params)
{
print_r($params);
$subdomain = isset($params['subdomain']) ? $params['subdomain'] : 'w3';
unset($params['subdomain']);
$path = parent::match($params);
if ($subdomain) {
$path = 'http://' . $subdomain . '.localhost' . $path;
}
return $path;
}
示例5: match
/**
* Skips pattern checking if invoked with Router::url(array(..., 'skipPatterns' => true));
*
* @param array $url
* @return mixed|void
*/
public function match($url)
{
if ($this->skipPatterns) {
$originalOptions = $this->options;
$this->options = array();
$res = parent::match($url);
$this->options = $originalOptions;
return $res;
} else {
return parent::match($url);
}
}
示例6: match
/**
* Checks if an URL array matches this route instance
*
* @param array $url An array of parameters to check matching with.
* @return mixed Either a string URL for the parameters if they match or false.
* @see CakeRoute::match()
*/
public function match($url)
{
if (isset($url['prefix']) && isset($url['action'])) {
$prefix = $url['prefix'];
$url['prefix'] = str_replace('_', '.', $url['prefix']);
$url['action'] = str_replace($prefix . '_', '', $url['action']);
}
$match = parent::match($url);
if ($match && isset($url['action']) && $url['action'] == 'index') {
$match = str_replace('/index', '', $match);
}
return $match;
}
示例7: match
/**
* Attempt to match a url array. If the url matches the route parameters + settings, then
* return a generated string url. If the url doesn't match the route parameters false will be returned.
* This method handles the reverse routing or conversion of url arrays into string urls.
*
* @param array $url An array of parameters to check matching with.
* @return mixed Either a string url for the parameters if they match or false.
*/
public function match($url)
{
if (empty($url['lang'])) {
$url['lang'] = $this->getDefaultLanguage();
}
$parentMatch = parent::match($url);
if (!$parentMatch) {
return false;
}
if ($this->_shouldStripDefaultLanguageOnMatch()) {
$parentMatch = preg_replace('#/' . DEFAULT_LANGUAGE . '/#', '/', $parentMatch);
}
return $parentMatch;
}
示例8: match
/**
* Attempt to match a url array. If the url matches the route parameters and
* settings, then return a generated string url. If the url doesn't match
* the route parameters, false will be returned. This method handles the
* reverse routing or conversion of url arrays into string urls.
*
* @param array $url An array of parameters to check matching with.
* @return mixed Either a string url for the parameters if they match or false.
*/
public function match($url)
{
// Looking for a route with routeName
if (!empty($url['routeName'])) {
// $this Route has no routeName and we are looking for one -> no match
if (empty($this->options['routeName'])) {
return false;
}
// $this Route has a different routeName than the one we are looking for -> no match
if ($url['routeName'] !== $this->options['routeName']) {
return false;
}
// Having reached here, the routeName matches, so we overwrite $url values
// with the ones from the matched route ($this). This way we ensure it
// finally matches when we pass it to parent::match()
foreach ($this->defaults as $key => $value) {
$url[$key] = $value;
}
unset($url['routeName']);
}
return parent::match($url);
}
示例9: testMatchNamedParametersArray
/**
* Test that match can handle array named parameters
*
* @return void
*/
public function testMatchNamedParametersArray()
{
$route = new CakeRoute('/:controller/:action/*');
$url = array('controller' => 'posts', 'action' => 'index', 'filter' => array('one', 'model' => 'value'));
$result = $route->match($url);
$expected = '/posts/index/filter%5B0%5D:one/filter%5Bmodel%5D:value';
$this->assertEquals($expected, $result);
$url = array('controller' => 'posts', 'action' => 'index', 'filter' => array('one', 'model' => array('two', 'order' => 'field')));
$result = $route->match($url);
$expected = '/posts/index/filter%5B0%5D:one/filter%5Bmodel%5D%5B0%5D:two/filter%5Bmodel%5D%5Border%5D:field';
$this->assertEquals($expected, $result);
}
示例10: testPatternOnAction
/**
* Testing that patterns on the :action param work properly.
*
* @return void
*/
public function testPatternOnAction()
{
$route = new CakeRoute('/blog/:action/*', array('controller' => 'blog_posts'), array('action' => 'other|actions'));
$result = $route->match(array('controller' => 'blog_posts', 'action' => 'foo'));
$this->assertFalse($result);
$result = $route->match(array('controller' => 'blog_posts', 'action' => 'actions'));
$this->assertEquals('/blog/actions/', $result);
$result = $route->parse('/blog/other');
$expected = array('controller' => 'blog_posts', 'action' => 'other', 'pass' => array(), 'named' => array());
$this->assertEquals($expected, $result);
$result = $route->parse('/blog/foobar');
$this->assertFalse($result);
}
示例11: match
function match($url)
{
if (isset($url['admin']) && $url['admin'] === true) {
if (isset($url['plugin']) && strtolower($url['plugin']) == 'admin') {
unset($url['plugin']);
unset($url['admin']);
$controller = isset($url['controller']) ? $url['controller'] . '/' : '';
$action = isset($url['action']) ? $url['action'] . '/' : '';
unset($url['controller']);
unset($url['action']);
return '/admin/' . $controller . $action . implode('/', array_values($url));
}
}
if (isset($url['default'])) {
if ($url['default']) {
return '/';
}
unset($url['default']);
}
if (!empty($url['slug'])) {
return $url['slug'];
}
return parent::match($url);
}
示例12: testMatchTrailing
/**
* Test match() with trailing ** style routes.
*
* @return void
*/
public function testMatchTrailing()
{
$route = new CakeRoute('/pages/**', array('controller' => 'pages', 'action' => 'display'));
$id = 'test/ spaces/漢字/la†în';
$result = $route->match(array('controller' => 'pages', 'action' => 'display', $id));
$expected = '/pages/test/%20spaces/%E6%BC%A2%E5%AD%97/la%E2%80%A0%C3%AEn';
$this->assertEquals($expected, $result);
}
示例13: CakeRoute
/**
* test match() with greedy routes, named parameters and passed args.
*
* @return void
*/
function testMatchWithNamedParametersAndPassedArgs()
{
Router::connectNamed(true);
$route = new CakeRoute('/:controller/:action/*', array('plugin' => null));
$result = $route->match(array('controller' => 'posts', 'action' => 'index', 'plugin' => null, 'page' => 1));
$this->assertEqual($result, '/posts/index/page:1');
$result = $route->match(array('controller' => 'posts', 'action' => 'view', 'plugin' => null, 5));
$this->assertEqual($result, '/posts/view/5');
$result = $route->match(array('controller' => 'posts', 'action' => 'view', 'plugin' => null, 5, 'page' => 1, 'limit' => 20, 'order' => 'title'));
$this->assertEqual($result, '/posts/view/5/page:1/limit:20/order:title');
$route =& new CakeRoute('/test2/*', array('controller' => 'pages', 'action' => 'display', 2));
$result = $route->match(array('controller' => 'pages', 'action' => 'display', 1));
$this->assertFalse($result);
$result = $route->match(array('controller' => 'pages', 'action' => 'display', 2, 'something'));
$this->assertEqual($result, '/test2/something');
$result = $route->match(array('controller' => 'pages', 'action' => 'display', 5, 'something'));
$this->assertFalse($result);
}
示例14: testMatchSimilarParameters
/**
* Test matching of parameters where one parameter name starts with another parameter name
*
* @return void
*/
public function testMatchSimilarParameters()
{
$route = new CakeRoute('/:thisParam/:thisParamIsLonger');
$url = array('thisParamIsLonger' => 'bar', 'thisParam' => 'foo');
$result = $route->match($url);
$expected = '/foo/bar';
$this->assertEquals($expected, $result);
}
示例15: match
/**
* Matches the model's id and converts it to a slug
*
* @param array $url Cake url array
* @return boolean
*/
public function match($url)
{
if (isset($this->options['models'])) {
foreach ($this->options['models'] as $checkNamed => $slugField) {
if (is_numeric($checkNamed)) {
$checkNamed = $slugField;
$slugField = null;
}
if (isset($url[$checkNamed])) {
$slugSet = $this->getSlugs($checkNamed, $slugField);
if (empty($slugSet)) {
continue;
}
if (isset($slugSet[$url[$checkNamed]])) {
$url[] = $slugSet[$url[$checkNamed]];
unset($url[$checkNamed]);
}
}
}
}
return parent::match($url);
}