2012-01-25 25 views
5

我遇到不規則行爲使用Zend控制器_redirect方法。Zend _redirect錯誤:前置基址兩次

我的應用程序副本是通過我的DocumentRoot中的符號鏈接產生的。另外我的默認路由器定製這種模式作出迴應:

http://localhost/<appSymLink>/<param_A>/<controller>/<action>/

從控制器,I構建像這樣一個URL:

$url = $this->_helper->url('action', 'controller', $param_A = 'valueA');

如果我訪問網址:

http://localhost/<appSymLink>/<param_A>/<controller>/<action>/

此變量包含以下字符串:

/<appSymLink>/<param_A>/<controller>/<action>/

而當我打電話

$this->_redirect($url);

用戶被顯式地重定向到該路徑,具有冗餘基路徑

/<appSymLink>/<appSymLink>/<param_A>/<controller>/<action>/

Zend公司似乎前面加上兩倍的基本路徑。

我的同事的申請副本居住在他的DocumentRoot,他沒有遇到這個問題。

定義一個空的基本路徑動作裏面,只是在操作之前,就像這樣:

$this->getRequest()->setBaseUrl('');

這不是一個可行的解決方案明顯。另一方面,在控制器插件routeShutdown內執行此操作可消除兩個應用程序目錄的出現。

有沒有人有任何建議解決這個問題,或任何提示進一步查看?

回答

6

如果使用從Url幫助程序生成的URL重定向,則需要通知重定向器它已經加上了基本URL的前綴。

只需使用以下

return $this->redirect($url, array('prependBase' => false)); 
4

嘗試並設置prependBase選項FALSE
$this->_redirect($url, array('prependBase' => FALSE);

Excerpt from ZF reference:

_redirect($url, array $options = array()): redirect to another location. This method takes a URL and an optional set of options. By default, it performs an HTTP 302 redirect.

The options may include one or more of the following:

exit: whether or not to exit immediately. If requested, it will cleanly close any open sessions and perform the redirect.

You may set this option globally within the controller using the setRedirectExit() accessor.

prependBase: whether or not to prepend the base URL registered with the request object to the URL provided.

You may set this option globally within the controller using the setRedirectPrependBase() accessor.

code: what HTTP code to utilize in the redirect. By default, an HTTP 302 is utilized; any code between 301 and 306 may be used.

You may set this option globally within the controller using the setRedirectCode() accessor.

如果這麼想的工作,我可以建議的動作助手 '重定向' 常用:
$this->_helper->getHelper('Redirector')->gotoSimple($action, $controller = null, $module = null, array $params = array())
Action Helper Redirector