使用してみてください:$this->getRequest()->getRequestUri()
要求された URI の最新情報を取得します。
ビュー スクリプトで次を使用$this->url()
します。現在の URL を取得します。
または、インスタンスを介して静的に統合された Zend Controller フロントを介して使用します。
$uri = Zend_Controller_Front::getInstance()->getRequest()->getRequestUri();
request() データの値を取得するために、シングルトン経由で URI 実装の値を取得できます。
$request = Zend_Controller_Front::getInstance()->getRequest();
$url = $request->getScheme() . '://' . $request->getHttpHost();
ビューでは、次のように使用します。
echo $this->serverUrl(true); # return with controller, action,...
例のようなハードコードは避けるべきです (使用しないでください!):
echo 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'];
この例の代わりに、ビューで as を使用します。
$uri = $this->getRequest()->getHttpHost() . $this->view->url();
ZEND で getRequest を使用したい場合は、The Request Objectを詳しく調べてください。
以下はスキップしてください(解剖例の仕組み)。
getRequestUri() がどのように機能するか、代わりに isRequest を使用する理由は$_SERVER
、プラットフォーム固有のデータがランダムに取得されるためです。
最初に uri が null の場合、次に IIS セットから要求された場合は HTTP_X_REWRITE_URL として設定されます。そうでない場合は、IIS7 で書き換えられた uri (エンコードされた uri を含む) を確認してください。IIS にない場合、REQUEST_URI は HTTP_HOSTNAME のスキームをチェックします。失敗した場合は、ORIG_PATH_INFO として使用して QUERY_STRING を取得します。
が設定されている場合、クラスで返されたオブジェクトの文字列を介して自動的にデータを取得します$this
。
失敗した場合は、設定よりも解析された文字列が設定されます。
if ($requestUri === null) {
if (isset($_SERVER['HTTP_X_REWRITE_URL'])) { // check this first so IIS will catch
$requestUri = $_SERVER['HTTP_X_REWRITE_URL'];
} elseif (
// IIS7 with URL Rewrite: make sure we get the unencoded url (double slash problem)
isset($_SERVER['IIS_WasUrlRewritten'])
&& $_SERVER['IIS_WasUrlRewritten'] == '1'
&& isset($_SERVER['UNENCODED_URL'])
&& $_SERVER['UNENCODED_URL'] != ''
) {
$requestUri = $_SERVER['UNENCODED_URL'];
} elseif (isset($_SERVER['REQUEST_URI'])) {
$requestUri = $_SERVER['REQUEST_URI'];
// Http proxy reqs setup request uri with scheme and host [and port] + the url path, only use url path
$schemeAndHttpHost = $this->getScheme() . '://' . $this->getHttpHost();
if (strpos($requestUri, $schemeAndHttpHost) === 0) {
$requestUri = substr($requestUri, strlen($schemeAndHttpHost));
}
} elseif (isset($_SERVER['ORIG_PATH_INFO'])) { // IIS 5.0, PHP as CGI
$requestUri = $_SERVER['ORIG_PATH_INFO'];
if (!empty($_SERVER['QUERY_STRING'])) {
$requestUri .= '?' . $_SERVER['QUERY_STRING'];
}
} else {
return $this;
}
} elseif (!is_string($requestUri)) {
return $this;
} else {
// Set GET items, if available
if (false !== ($pos = strpos($requestUri, '?'))) {
// Get key => value pairs and set $_GET
$query = substr($requestUri, $pos + 1);
parse_str($query, $vars);
$this->setQuery($vars);
}
}
$this->_requestUri = $requestUri;
return $this;