Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

zend framework 2 base path access in controller

How can i call basePath helper in controller in ZF 2. I have to redirect to a particular url in which i need base path. return $this->redirect()->toUrl($basePath.'/application/rent/search');

like image 511
Dilip Prajapati Avatar asked Dec 20 '22 12:12

Dilip Prajapati


1 Answers

The full base url (http://...) can be determined from within the controller as follows:

$event = $this->getEvent();
$request = $event->getRequest();
$router = $event->getRouter();
$uri = $router->getRequestUri();
$baseUrl = sprintf('%s://%s%s', $uri->getScheme(), $uri->getHost(), $request->getBaseUrl());
like image 119
aimfeld Avatar answered Jan 05 '23 13:01

aimfeld