Skip to content

Commit

Permalink
Update Sitemap ViewHelper after Url ViewHelper
Browse files Browse the repository at this point in the history
Sitemap ViewHelper has a dependency to Url ViewHelper in url() method. It calls with defaults parameters. In ZF1, a route keep values between match() and assemble() methods in the same instance.

This behavior is broken in ZF2 (at this time). We don't have a default route or a current route in Mvc\Router: we must define route to call Url ViewHelper. Why Sitemap ViewHelper need the "current document"? I try to replace this behavior with BaseUrl ViewHelper. Wait & see...
  • Loading branch information
b-durand committed Oct 28, 2011
1 parent 56df22f commit b882a64
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 20 deletions.
4 changes: 2 additions & 2 deletions library/Zend/View/Helper/Navigation/Sitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,8 @@ public function url(AbstractPage $page)
$url = (string) $href;
} else {
// href is relative to current document; use url helpers
$urlHelper = $this->getView()->plugin('url');
$curDoc = $urlHelper();
$baseUrlHelper = $this->getView()->plugin('baseurl');
$curDoc = $baseUrlHelper();
$curDoc = ('/' == $curDoc) ? '' : trim($curDoc, '/');
$url = rtrim($this->getServerUrl(), '/') . '/'
. $curDoc
Expand Down
18 changes: 0 additions & 18 deletions tests/Zend/View/Helper/Navigation/SitemapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@
*/
class SitemapTest extends AbstractTest
{
protected $_front;
protected $_oldRequest;
protected $_oldRouter;
protected $_oldServer = array();

/**
Expand Down Expand Up @@ -85,28 +82,13 @@ protected function setUp()
$_SERVER['SERVER_PORT'] = 80;
$_SERVER['REQUEST_URI'] = '/';

$this->_front = \Zend\Controller\Front::getInstance();
$this->_oldRequest = $this->_front->getRequest();
$this->_oldRouter = $this->_front->getRouter();

$this->_front->resetInstance();
$this->_front->setRequest(new Request\Http());
$this->_front->getRouter()->addDefaultRoutes();

parent::setUp();

$this->_helper->setFormatOutput(true);
}

protected function tearDown()
{
if (null !== $this->_oldRequest) {
$this->_front->setRequest($this->_oldRequest);
} else {
$this->_front->setRequest(new Request\Http());
}
$this->_front->setRouter($this->_oldRouter);

foreach ($this->_oldServer as $key => $value) {
$_SERVER[$key] = $value;
}
Expand Down

0 comments on commit b882a64

Please sign in to comment.