本文整理汇总了PHP中sfRoute::generate方法的典型用法代码示例。如果您正苦于以下问题:PHP sfRoute::generate方法的具体用法?PHP sfRoute::generate怎么用?PHP sfRoute::generate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sfRoute
的用法示例。
在下文中一共展示了sfRoute::generate方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generate
/**
* Generates a URL from the given parameters.
*
* @param mixed $params The parameter values
* @param array $context The context
* @param Boolean $absolute Whether to generate an absolute URL
*
* @return string The generated URL
*/
public function generate($params, $context = array(), $absolute = false)
{
$slug = null;
if (isset($params['engine-slug'])) {
$slug = $params['engine-slug'];
aRouteTools::pushTargetEnginePage($slug);
unset($params['engine-slug']);
}
// Note that you must pass false to parent::generate for the $absolute parameter
$result = aRouteTools::addPageToUrl($this, parent::generate($params, $context, false), $absolute);
if ($slug) {
aRouteTools::popTargetEnginePage($slug);
}
return $result;
}
示例2: generate
public function generate($params, $context = array(), $absolute = false)
{
$url = parent::generate($params, $context, $absolute);
return 'http://' . $context['host'] . $url;
}
示例3: tokenizeBufferBefore
$t->diag('->parseStarParameter()');
$route = new sfRoute('/foo/*');
$t->is($route->matchesUrl('/foo/foo/bar/bar/foo'), array('foo' => 'bar', 'bar' => 'foo'), '->parseStarParameter() parses * as key/value pairs');
$t->is($route->matchesUrl('/foo/foo/foo.bar'), array('foo' => 'foo.bar'), '->parseStarParameter() uses / as the key/value separator');
$t->is($route->matchesUrl('/foo'), array(), '->parseStarParameter() returns no additional parameters if the * value is empty');
$route = new sfRoute('/foo/*', array('module' => 'foo'));
$t->is($route->matchesUrl('/foo/foo/bar/module/barbar'), array('foo' => 'bar', 'module' => 'foo'), '->parseStarParameter() cannot override a default value');
$route = new sfRoute('/:foo/*');
$t->is($route->matchesUrl('/bar/foo/barbar'), array('foo' => 'bar'), '->parseStarParameter() cannot override pattern variables');
$route = new sfRoute('/foo/*/bar');
$t->is($route->matchesUrl('/foo/foo/bar/bar'), array('foo' => 'bar'), '->parseStarParameter() is able to parse a star in the middle of a rule');
$t->is($route->matchesUrl('/foo/bar'), array(), '->parseStarParameter() is able to parse a star if it is empty');
// ->generateStarParameter()
$t->diag('->generateStarParameter()');
$route = new sfRoute('/foo/:foo/*');
$t->is($route->generate(array('foo' => 'bar', 'bar' => 'foo')), '/foo/bar/bar/foo', '->generateStarParameter() replaces * with all the key/pair values that are not variables');
// custom token
$t->diag('custom token');
class MyRoute extends sfRoute
{
protected function tokenizeBufferBefore(&$buffer, &$tokens, &$afterASeparator, &$currentSeparator)
{
if ($afterASeparator && preg_match('#^=(' . $this->options['variable_regex'] . ')#', $buffer, $match)) {
// a labelled variable
$this->tokens[] = array('label', $currentSeparator, $match[0], $match[1]);
$currentSeparator = '';
$buffer = substr($buffer, strlen($match[0]));
$afterASeparator = false;
} else {
return false;
}
示例4: generate
/**
* @see sfRoute
*/
public function generate($params, $context = array(), $absolute = false)
{
return parent::generate($this->filterParams($params), $context, $absolute);
}
示例5: generate
/**
* Generates a URL from the given parameters.
*
* @param mixed $params The parameter values
* @param array $context The context
* @param Boolean $absolute Whether to generate an absolute URL
*
* @return string The generated URL
*/
public function generate($params, $context = array(), $absolute = false)
{
unset($params['sf_method']);
return parent::generate($params, $context, $absolute);
}
示例6: generate
/**
* Generates a URL from the given parameters.
*
* @param mixed $params The parameter values
* @param array $context The context
* @param Boolean $absolute Whether to generate an absolute URL
*
* @return string The generated URL
*/
public function generate($params, $context = array(), $absolute = false)
{
// Note that you must pass false to parent::generate for the $absolute parameter
return aRouteTools::addPageToUrl($this, parent::generate($params, $context, false), $absolute);
}