Hi Olivier,

i stumbled across the same issue.
My workarond was to build my own route class which modifies the assemble
method.
Now if reset is true assemble takes account of my given parameters but
resets the request parameters..

Hope that helps

Bye
Jens


Olivier Sirven schrieb:
> Hi,
>
> I have created a route this way:
> $router = new Zend_Controller_Router_Rewrite();
> $route = new Zend_Controller_Router_Route('/*',
>                                           array('controller' => 'index',
>                                                 'action' => 'index'));
> $router->addRoute('root', $route);
> And the current request uri is something like this:
> /key1/value1/key2/value2
>
> Within a view I use the Url helper like this:
> echo $this->url(array('key1' => 'newvalue'), 'root');
>
> I thought it should returns something like "/key1/newvalue" but it returns 
> something like "/key1/newvalue/key2/value2".
> I have tried to add the "reset" parameter to true but then I don't have any 
> parameter at all, just "/":
> echo $this->url(array('key1' => 'newvalue'), 'root', true);
>
> Is it a bug or a feature? 
> If this is a feature, is there a way to assemble a wildcard route without 
> taking into account the current parameters?
>
>   

    /**
     * Assembles user submitted parameters forming a URL path defined by this 
route
     *
     * @param array An array of variable and value pairs used as parameters
     * @return string Route path with user submitted parameters
     */
    public function assemble($data = array(), $reset = false)
    {

        $url = array();
        foreach ($this->_parts as $key => $part) {
            $resetPart = false;
            if (isset($part['name']) && array_key_exists($part['name'], $data) 
&& $data[$part['name']] === null) {
                $resetPart = true;
            }


            if (isset($part['name'])) {

                if (isset($data[$part['name']]) && !$resetPart) {
                    $url[$key] = $data[$part['name']];
                    unset($data[$part['name']]);
                } elseif (!$reset && !$resetPart && 
isset($this->_values[$part['name']])) {
                    $url[$key] = $this->_values[$part['name']];
                } elseif (!$reset && !$resetPart && 
isset($this->_params[$part['name']])) {
                    $url[$key] = $this->_params[$part['name']];
                } elseif (isset($this->_defaults[$part['name']])) {
                    $url[$key] = $this->_defaults[$part['name']];
                } else
                    throw new Zend_Controller_Router_Exception($part['name'] . 
' is not specified');

            } else {
                if ($part['regex'] != '\*') {
                    $url[$key] = $part['regex'];
                } else {
                        if (!$reset) {
                            $wildcards = $data + $this->_params;
                        } else {
                                $wildcards = $data;
                        }
                        foreach ($wildcards as $var => $value) {
                          if ($value !== null) {
                                    $url[$var] = $var . self::URI_DELIMITER . 
$value;
                          }
                        }
                }
            }

        }
        return implode(self::URI_DELIMITER, $url);
    }

Reply via email to