get current page url and change action

﹥>﹥吖頭↗ 提交于 2020-01-01 05:07:05

问题


I need to give current page url and change action url. After that I want echo that in view file. I want do these in view file, not controller!

Do you have any idea?


回答1:


You can get current page url as follows:

  $uri = Zend_Controller_Front::getInstance()->getRequest()->getRequestUri();

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

The view helper $this->userAgent() returns an instance of Zend_Http_UserAgent that can provide you with many useful info.

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 'changing an action'. You want to change it when you echo it, or you want to redirect user. Anyway, hope this will help.




回答2:


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

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



回答3:


$front = Zend_Controller_Front::getInstance();
$fullUrl = 'http://' .
$front->getRequest()->getHttpHost() .
$front->getRequest()->getRequestUri();

Don't forget protocol(in this example http://) if you are going to use $fullUrl for href attributes




回答4:


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

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

If you're echoing out the (user supplied) URL on the page, it's a good idea to use htmlspecialchars() to avoid someone sending your users to http://example.com/?q=<script>nastyBusiness()</script>.



来源:https://stackoverflow.com/questions/5926924/get-current-page-url-and-change-action

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!