How to change the separation character of Zend Url?

做~自己de王妃 提交于 2019-12-12 04:30:29

问题


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:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/2789129/how-to-change-the-separation-character-of-zend-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!