本文整理汇总了PHP中Zend_Controller_Router_Route::assemble方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Controller_Router_Route::assemble方法的具体用法?PHP Zend_Controller_Router_Route::assemble怎么用?PHP Zend_Controller_Router_Route::assemble使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Controller_Router_Route
的用法示例。
在下文中一共展示了Zend_Controller_Router_Route::assemble方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: assemble
public function assemble($data = array(), $reset = false, $encode = false)
{
$return = parent::assemble($data, $reset, $encode);
if ($this->_representationParam !== null) {
if ($return && isset($data[$this->_representationParam])) {
$return .= '.' . $data[$this->_representationParam];
}
}
return $return;
}
示例2: assemble
/**
* Assembles user submitted parameters forming a URL path defined by this route
*
* @param array $ An array of variable and value pairs used as parameters
* @param boolean $reset Whether or not to set route defaults with those provided in $data
* @return string Route path with user submitted parameters
*/
public function assemble($data = array(), $reset = false, $encode = false, $partial = false)
{
// TODO: We should take the paramValues/mvcParams into account shouldn't we? For now
// This router doesn't support full reverse assembly I guess.
return parent::assemble($data, $reset, $encode, $partial);
}
示例3: testEscapedSpecialCharsWithTranslation
public function testEscapedSpecialCharsWithTranslation()
{
$route = new Zend_Controller_Router_Route('::foo/@@bar/:@myvar');
$path = $route->assemble(array('myvar' => 'foo'));
$this->assertEquals($path, ':foo/@bar/en_foo');
$values = $route->match(':foo/@bar/en_foo');
$this->assertEquals($values['myvar'], 'foo');
}
示例4: testAssembleWithRemovedDefaults
public function testAssembleWithRemovedDefaults() // Test for ZF-1197
{
$route = new Zend_Controller_Router_Route(':controller/:action/*', array('controller' => 'index', 'action' => 'index'));
$url = $route->assemble(array('id' => 3));
$this->assertSame('index/index/id/3', $url);
$url = $route->assemble(array('action' => 'test'));
$this->assertSame('index/test', $url);
$url = $route->assemble(array('action' => 'test', 'id' => 3));
$this->assertSame('index/test/id/3', $url);
$url = $route->assemble(array('controller' => 'test'));
$this->assertSame('test', $url);
$url = $route->assemble(array('controller' => 'test', 'action' => 'test'));
$this->assertSame('test/test', $url);
$url = $route->assemble(array('controller' => 'test', 'id' => 3));
$this->assertSame('test/index/id/3', $url);
$url = $route->assemble(array());
$this->assertSame('', $url);
$route->match('ctrl');
$url = $route->assemble(array('id' => 3));
$this->assertSame('ctrl/index/id/3', $url);
$url = $route->assemble(array('action' => 'test'));
$this->assertSame('ctrl/test', $url);
$url = $route->assemble();
$this->assertSame('ctrl', $url);
$route->match('index');
$url = $route->assemble();
$this->assertSame('', $url);
}
示例5: assemble
/**
* Assembles user submitted parameters forming a URL path defined by this route
*
* We cannot generate http://subdomain.domain.com/ due to the fact
* that the url helper adds the baseUrl in front of it... *sigh*
*
* @todo figure out a workaround
*
* @param array $data An array of variable and value pairs used as parameters
* @param boolean $reset Whether or not to set route defaults with those provided in $data
* @return string Route path with user submitted parameters
*/
public function assemble($data = array(), $reset = false)
{
return parent::assemble($data, $reset);
}
示例6: testAssembleWithVariableMissing
public function testAssembleWithVariableMissing()
{
$route = new Zend_Controller_Router_Route('archive/:year', array('controller' => 'archive', 'action' => 'show'), array('year' => '\\d+'));
try {
$url = $route->assemble();
} catch (Exception $e) {
}
$this->assertTrue($e instanceof Zend_Controller_Router_Exception, 'Expected Zend_Controller_Router_Exception to be thrown');
}
示例7: testAssembleWithUrlVariablesReuse
public function testAssembleWithUrlVariablesReuse()
{
$route = new Zend_Controller_Router_Route('archives/:year/:month');
$values = $route->match('archives/2006/07');
$this->assertType('array', $values);
$url = $route->assemble(array('month' => '03'));
$this->assertSame('archives/2006/03', $url);
}
示例8: testAssembleWithDefaultAndValue
public function testAssembleWithDefaultAndValue()
{
$route = new Zend_Controller_Router_Route('authors/:name', array('name' => 'martel'));
$url = $route->assemble(array('name' => 'mike'));
$this->assertEquals('authors/mike', $url);
}
示例9: assemble
/**
* Assembles user submitted parameters forming a URL path defined by this route
*
* @param array $data An array of variable and value pairs used as parameters
* @param boolean $reset Whether or not to set route defaults with those provided in $data
* @return string Route path with user submitted parameters
*/
public function assemble($data = array(), $reset = false, $encode = false, $partial = false)
{
if (!isset($data['locale'])) {
return parent::assemble($data, $reset, $encode, $partial);
}
$locale = $data['locale'];
unset($data['locale']);
$assemble = parent::assemble($data, $reset, $encode);
if (in_array($locale, self::$_locales)) {
if (isset($this->_defaults['locale'])) {
$defaultLocale = $this->_defaults['locale'];
} else {
$defaultLocale = self::$_defaultLocale;
}
if ($locale != $defaultLocale) {
$assemble = implode($this->_urlDelimiter, array($locale, $assemble));
}
}
return $assemble;
}
示例10: testEncode
public function testEncode()
{
$route = new Zend_Controller_Router_Route(':controller/:action/*', array('controller' => 'index', 'action' => 'index'));
$url = $route->assemble(array('controller' => 'My Controller'), false, true);
$this->assertEquals('My+Controller', $url);
$url = $route->assemble(array('controller' => 'My Controller'), false, false);
$this->assertEquals('My Controller', $url);
$token = $route->match('en/foo/id/My Value');
$url = $route->assemble(array(), false, true);
$this->assertEquals('en/foo/id/My+Value', $url);
$url = $route->assemble(array('id' => 'My Other Value'), false, true);
$this->assertEquals('en/foo/id/My+Other+Value', $url);
$route = new Zend_Controller_Router_Route(':controller/*', array('controller' => 'My Controller'));
$url = $route->assemble(array('id' => 1), false, true);
$this->assertEquals('My+Controller/id/1', $url);
}
示例11: testAssembleResetDefaults
public function testAssembleResetDefaults()
{
$route = new Zend_Controller_Router_Route(':controller/:action/*', array('controller' => 'index', 'action' => 'index'));
$values = $route->match('news/view/id/3');
$url = $route->assemble(array('action' => null));
$this->assertSame('news/index/id/3', $url);
$url = $route->assemble(array('action' => null, 'id' => null));
$this->assertSame('news/index', $url);
}
示例12: assemble
/**
* Assembles user submitted parameters forming a URL path defined by this route
*
* @param array $data An array of variable and value pairs used as parameters
* @param boolean $reset Whether or not to set route defaults with those provided in $data
* @return string Route path with user submitted parameters
*/
public function assemble($data = array(), $reset = false, $encode = false, $partial = false)
{
$locale = null;
if (!empty($data['locale'])) {
// This locale is always valid. It's a developer filtered input
$locale = trim($data['locale'], '/ ');
} else {
$locale = trim(Axis_Locale::getLanguageUrl(), '/ ');
}
unset($data['locale']);
$assemble = parent::assemble($data, $reset, $encode, $partial);
if (empty($locale)) {
return $assemble;
}
$isValidLocale = false;
foreach (self::$_locales as $_locale) {
if (strpos($_locale, $locale) === 0) {
$isValidLocale = true;
break;
}
}
if ($isValidLocale) {
if (isset($this->_defaults['locale'])) {
$defaultLocale = $this->_defaults['locale'];
} else {
$defaultLocale = self::$_defaultLocale;
}
if ($locale != $defaultLocale) {
if (empty($assemble)) {
// preventing urlDelimiter at the end of the url for the homepage
$assemble = $locale;
} else {
$assemble = implode($this->_urlDelimiter, array($locale, $assemble));
}
}
}
return $assemble;
}
示例13: _buildQuery
/**
* Builds the query part of the URL
*/
protected function _buildQuery()
{
$event = new Erfurt_Event('onBuildUrl');
$event->base = $this->_base;
$event->route = $this->_route;
$event->controller = $this->_controller;
$event->action = $this->_action;
$event->params = $this->_params;
$urlCreated = $event->trigger();
if ($event->handled()) {
if ($urlCreated && isset($event->url)) {
return $event->url;
} else {
$this->_params = $event->params;
$this->_controller = $event->controller;
$this->_action = $event->action;
$this->_route = $event->route;
}
}
// check params
foreach ($this->_params as $name => $value) {
if (is_string($value) && preg_match('/\\//', $value)) {
$this->_useSefUrls = false;
}
}
$url = '';
if ($this->_route) {
// checking if reset of route-defaults necessary
// fixes pager usage fails on versioning pages
if (count($this->_route->getDefaults()) == 0) {
$resetRoute = false;
} else {
$resetRoute = true;
}
if ($this->_useSefUrls) {
// let the route assemble the whole URL
$url = $this->_route->assemble($this->_params, $resetRoute, true);
} else {
// we will assign parameters ourselves
$url = $this->_route->assemble(array(), $resetRoute);
$url = sprintf('%s/%s', $url, '?' . http_build_query($this->_params, '&'));
}
} else {
if ($this->_useSefUrls) {
$query = '';
$lastKey = '';
foreach ($this->_params as $key => $value) {
if (is_scalar($value)) {
$value = urlencode($value);
$query .= "{$key}/{$value}/";
$lastKey = $key;
}
}
// remove trailing slash
$query = rtrim($query, '/');
} else {
$query = '?' . http_build_query($this->_params, '&');
}
$parts = array_filter(array($this->_controller, $this->_action, $query));
$url = implode('/', $parts);
}
// HACK:
$this->_useSefUrls = true;
return $this->_base . ltrim($url, '/');
}