Michoser
Michoser

Reputation: 85

How to get current route in zend 2 framework?

How to check in index action If I am at www.sample.com/test not at www.sample.com/test/qqqq or www.sample.com/test?testget=fdfdf&testget2=fdfdfdf or at others sites just only at www.sample.com/test ?

Upvotes: 0

Views: 729

Answers (3)

Michoser
Michoser

Reputation: 85

$event = $this->getEvent();

$event->getRouteMatch();

Upvotes: 1

itrascastro
itrascastro

Reputation: 785

In a view you can use

echo $this->serverUrl(true);

You can also use view helpers in a controller

$viewHelperManager = $this->getServiceLocator()->get('ViewHelperManager'); 

$myHelper = $viewHelperManager->get('serverUrl');

Upvotes: 0

Romario Lopez C
Romario Lopez C

Reputation: 174

In zf1 this was straightforward with applicationPath or rootPath but in zf2 this has changed.

Found more information here http://samminds.com/2012/08/why-root_path-is-not-needed/

Hope it helps

Upvotes: 0

Related Questions