views:

83

answers:

2

I use Zend URL view helper for building my urls. Everythings works exactly as I'd like to, except one thing: The character used for replacing spaces in the url is a plus (+). I'd like it to be a 'min' (-). How can I change this?

Example: Now: /nl/nieuws/bericht/3/title/nieuwe*+affiches Wish: /nl/nieuws/bericht/3/title/nieuwe-*affiches

Thanks in advcance!

+1  A: 

This isn't in the documentation anywhere, but it appears that the Zend URL view helper can take a parameter in it's $urlOptions array called chainNameSeparator. No guarantee that's what you're looking for, but trying playing with that and see if it changes anything.

ABach
This is the result of a `urlencode()` happening on one of the parameters. The `chainNameSeparator` is used when chaining routes. I think maybe you were thinking of `setWordDelimiter()` in `Zend_Controller_Dispatcher_Abstract`.
awgy
Ahh, I see - it's been some time since I used ZF.
ABach
+1  A: 

This is likely happening because, by default, Zend_View_Helper_Url will urlencode() what you send it, which would translate spaces into +. My suggestion to you would be to create a new view helper for the type of URL in your code that needs the special inflection.

Something like:

class Default_View_Helper_SpecialUrl extends Zend_View_Helper_Abstract
{
    public function specialUrl(array $opts = array(), $name = null, $reset = false, $encode = true)
    {
        if (!empty($opts['whatever'])) {
            $opts['whatever'] = str_replace(' ', '-', $opts['whatever']);
        }

        $router = Zend_Controller_Front::getInstance()->getRouter();
        return $router->assemble($opts, $name, $reset, $encode);
    }
}

This way the spaces are changed for whatever necessary route parameters before URL encoding happens by the router.

awgy