Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'hotfix/4084'

Close #4084
  • Loading branch information...
commit bddc55381db7fbbc910773dc4b7bf06a10837206 2 parents a0117af + 108e806
@weierophinney weierophinney authored
View
42 library/Zend/Navigation/Page/Mvc.php
@@ -35,6 +35,13 @@ class Mvc extends AbstractPage
protected $controller;
/**
+ * URL query part to use when assembling URL
+ *
+ * @var array|string
+ */
+ protected $query;
+
+ /**
* Params to use when assembling URL
*
* @see getHref()
@@ -205,14 +212,19 @@ public function getHref()
}
$options = array('name' => $name);
- $url = $router->assemble($params, $options);
// Add the fragment identifier if it is set
$fragment = $this->getFragment();
if (null !== $fragment) {
- $url .= '#' . $fragment;
+ $options['fragment'] = $fragment;
+ }
+
+ if (null !== ($query = $this->getQuery())) {
+ $options['query'] = $query;
}
+ $url = $router->assemble($params, $options);
+
return $this->hrefCache = $url;
}
@@ -285,6 +297,32 @@ public function getController()
}
/**
+ * Sets URL query part to use when assembling URL
+ *
+ * @see getHref()
+ * @param array|string|null $query URL query part
+ * @return self fluent interface, returns self
+ */
+ public function setQuery($query)
+ {
+ $this->query = $query;
+ $this->hrefCache = null;
+ return $this;
+ }
+
+ /**
+ * Returns URL query part to use when assembling URL
+ *
+ * @see getHref()
+ *
+ * @return array|string|null URL query part (as an array or string) or null
+ */
+ public function getQuery()
+ {
+ return $this->query;
+ }
+
+ /**
* Sets params to use when assembling URL
*
* @see getHref()
View
38 tests/ZendTest/Navigation/Page/MvcTest.php
@@ -215,6 +215,44 @@ public function testGetHrefWithFragmentIdentifier()
$this->assertEquals('/lolcat/myaction/1337#qux', $page->getHref());
}
+ public function testGetHrefPassesQueryPartToRouter()
+ {
+ $page = new Page\Mvc(array(
+ 'label' => 'foo',
+ 'query' => 'foo=bar&baz=qux',
+ 'controller' => 'mycontroller',
+ 'action' => 'myaction',
+ 'route' => 'myroute',
+ 'params' => array(
+ 'page' => 1337
+ )
+ ));
+
+ $route = new RegexRoute(
+ '(lolcat/(?<action>[^/]+)/(?<page>\d+))',
+ '/lolcat/%action%/%page%',
+ array(
+ 'controller' => 'foobar',
+ 'action' => 'bazbat',
+ 'page' => 1,
+ )
+ );
+ $this->router->addRoute('myroute', $route);
+ $this->routeMatch->setMatchedRouteName('myroute');
+
+ $page->setRouteMatch($this->routeMatch);
+ $page->setRouter($this->router);
+
+ $this->assertEquals('/lolcat/myaction/1337?foo=bar&baz=qux', $page->getHref());
+
+ // Test with array notation
+ $page->setQuery(array(
+ 'foo' => 'bar',
+ 'baz' => 'qux',
+ ));
+ $this->assertEquals('/lolcat/myaction/1337?foo=bar&baz=qux', $page->getHref());
+ }
+
public function testIsActiveReturnsTrueOnIdenticalControllerAction()
{
$page = new Page\Mvc(array(
Please sign in to comment.
Something went wrong with that request. Please try again.