Get current page url and change action

I need to specify the current page url and change the action url. After that, I want the echo to appear in the view file. I want to do this in the view file, not in the controller!

Do you have any ideas?

+6
source share
4 answers

You can get the current page url as follows:

$uri = Zend_Controller_Front::getInstance()->getRequest()->getRequestUri(); // or using userAgent view helper: $uri = $this->userAgent()->getServerValue('request_uri'); 

A helper of the form $this->userAgent() returns an instance of Zend_Http_UserAgent , which can provide you with a lot of useful information.

If you want to get an action in your views, you can get it as follows:

 Zend_Controller_Front::getInstance()->getRequest()->getActionName(); 

Not sure what you mean by โ€œchange of actionโ€. Do you want to change it when you echo it or want to redirect the user. Anyway, hope this helps.

+19
source

If your current scope is a controller action, you can do this:

 $uri = $this->view->serverUrl() . $this->view->url(); 
+4
source

$ front = Zend_Controller_Front :: getInstance ();
$ fullUrl = 'http: //'.
$ front-> getRequest () โ†’ getHttpHost ().
$ Front-> GetRequest () โ†’ getRequestUri ();

Do not forget the protocol (in this example http:// ) if you intend to use the attributes $fullUrl for href

+1
source

Late for the party for sure, but the following worked for me in the Zend 1 project:

 <?php echo htmlspecialchars($this->serverUrl(true)); ?> 

If you echo the URL (the page provided by the user) on the page, it is recommended to use htmlspecialchars () so that someone does not send your users to http://example.com/?q=<script>nastyBusiness()</script> .

0
source

Source: https://habr.com/ru/post/887551/


All Articles