ZF-10465: Add option 'encodeUrl' to Zend_Page_MVC config
Description
Zend_Page_MVC has the option to switch whether params should be reset when assembling URL. There are some cases where some params contain characters (like '/') which needs to be preserved by some routes. So there needs to be a way of sitching encodeUrl.
E.g.: You have a route for content-pages like this
'content' => array(
'type' => 'Zend_Controller_Router_Route_Regex',
'route' => '(.+)\.html',
'defaults' => array(
'module' => 'default',
'controller' => 'content',
'action' => 'content'
),
'map' => array(
1 => 'contentKey'
),
'reverse' => '%s.html'
),
And later on you want to define some subpages via Zend_Navigation:
array(
'label' => 'PageXY',
'route' => 'content',
'module' => 'default',
'controller' => 'content',
'action' => 'content',
'params' => array(
'contentKey' => 'pagexy/subpage'
)
),
This results in an invalid href, because Zend_Page_MVC calls a url-helper (Zend_Controller_Action_Helper_Url) internally, but there is no way to pass a configuration variable which controls the parameter '$encode' of url-helper
Comments
Posted by Ulrich Beckers (ubeckers) on 2010-09-17T02:11:08.000+0000
I changed the code of class Zend_Navigation_Page_Mvc in my setup, so there is a way to control the url encoding. Maybe there is a way this can be applied to further ZF-Version?
<?php /** * Zend Framework * * LICENSE * * This source file is subject to the new BSD license that is bundled * with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://framework.zend.com/license/new-bsd * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to license@zend.com so we can send you a copy immediately. * * @category Zend * @package Zend_Navigation * @subpackage Page * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License * @version $Id: Mvc.php 20096 2010-01-06 02:05:09Z bkarwin $ */
/** * @see Zend_Navigation_Page */ require_once 'Zend/Navigation/Page.php';
/** * @see Zend_Controller_Action_HelperBroker */ require_once 'Zend/Controller/Action/HelperBroker.php';
/** * Used to check if page is active * * @see Zend_Controller_Front */ require_once 'Zend/Controller/Front.php';
/** * Represents a page that is defined using module, controller, action, route * name and route params to assemble the href * * @category Zend * @package Zend_Navigation * @subpackage Page * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Navigation_Page_Mvc extends Zend_Navigation_Page { /** * Action name to use when assembling URL * * @var string */ protected $_action;
}
Posted by Kai Uwe (kaiuwe) on 2011-01-26T00:39:19.000+0000
Added code tags
Posted by Kai Uwe (kaiuwe) on 2011-01-26T00:44:32.000+0000
Hi Ulrich, can you add a patch file for this and some tests? Thanks.
Posted by Ulrich Beckers (ubeckers) on 2011-01-26T03:03:36.000+0000
Ok, here is the patch file. I don't know how to attach a file here, so I just Post it..
--- Mvc_Orig.php 2010-01-06 03:05:09.000000000 +0100 +++ Mvc.php 2011-01-26 11:57:51.000000000 +0100 @@ -93,6 +93,14 @@ * @var bool */ protected $_resetParams = true; +
+ /** + * Whether href should be encoded when assembling URL + * + * @see getHref() + * @var bool + */ + protected $_encodeUrl = true;
@@ -201,7 +209,9 @@
- $this->getResetParams()); + $this->getResetParams(), + $this->getEncodeUrl() + );
@@ -403,6 +413,34 @@ { return $this->_resetParams; } +
+ /** + * Sets whether href should be encoded when assembling URL + * + * @see getHref() + * + * @param bool $resetParams whether href should be encoded when + * assembling URL + * @return Zend_Navigation_Page_Mvc fluent interface, returns self + */ + public function setEncodeUrl($encodeUrl) + { + $this->_encodeUrl = (bool) $encodeUrl; + $this->_hrefCache = null; + return $this; + } +
+ /** + * Returns whether herf should be encoded when assembling URL + * + * @see getHref() + * + * @return bool whether herf should be encoded when assembling URL + */ + public function getEncodeUrl() + { + return $this->_encodeUrl; + }
@@ -434,7 +472,8 @@ 'module' => $this->getModule(), 'params' => $this->getParams(), 'route' => $this->getRoute(), - 'reset_params' => $this->getResetParams() + 'reset_params' => $this->getResetParams(), + 'encodeUrl' => $this->getEncodeUrl(), )); } }
Posted by Kai Uwe (kaiuwe) on 2011-01-26T03:09:05.000+0000
Please add code tags!
Posted by Ulrich Beckers (ubeckers) on 2011-01-26T04:18:25.000+0000
Sorry!
Posted by Kai Uwe (kaiuwe) on 2011-01-28T08:04:35.000+0000
Thanks for your help! I will write some test cases.
Posted by Kai Uwe (kaiuwe) on 2011-06-06T11:22:19.000+0000
Unit tests
Posted by Frank Brückner (frosch) on 2011-07-29T07:33:57.000+0000
Extended unit test attached.
Posted by Pádraic Brady (padraic) on 2011-09-04T13:02:50.000+0000
Fixed in r24444 and via ZF2 PR