示例#1
0
 /**
  * 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
0
 public function generate($params, $context = array(), $absolute = false)
 {
     $url = parent::generate($params, $context, $absolute);
     return 'http://' . $context['host'] . $url;
 }
示例#3
0
$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;
        }
 /**
  * @see sfRoute
  */
 public function generate($params, $context = array(), $absolute = false)
 {
     return parent::generate($this->filterParams($params), $context, $absolute);
 }
 /**
  * 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
0
文件: aRoute.php 项目: verenate/gri
 /**
  * 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);
 }