問題描述
我希望有人向我解釋 _forward 到底在做什么,我看不到 _forward 是否也在將附加視圖渲染到操作或只是執行操作.
I would like someone to explain me what _forward is exactly doing, I cannot see if _forward is also rendering the attached view to the action or just executing the action.
還可以在視圖腳本中將參數傳遞給 $this->action 嗎?
Also is it possible to pass argument to $this->action in a view script ?
更一般地說,我的問題是如何編寫確認頁面,假設用戶輸入了一些東西并且您想向他顯示確認,對于這種情況是向前的嗎?
More generally my problem is how to code a confirmation page, let's say the user input some stuff and you want to show him confirmation, is forward is mean for that case ?
推薦答案
_forward 是內部重定向._redirect 發送的標頭告訴客戶端的瀏覽器轉到某個其他 URL,而 _forward 則告訴 Dispatcher 在內部將請求重定向到其他地方.
_forward is an internal redirect. Where as _redirect sends a header that tells the client's browser to go to some other URL, _forward tells the Dispatcher to internally redirect the request somewhere else.
如果考慮正常的發貨順序:
If you consider the normal dispatch order of:
preDispatch()
someAction()
postDispatch()
在該進程中的任何一點調用 _forward 都會導致以下步驟無法執行.因此,如果您在 preDispatch() 中調用 _forward,則不會調用 someAction() 等等.如果您在 someAction() 中使用 _forward() 并且您正在使用 viewRenderer 操作助手來呈現您的視圖(您讓框架選擇要呈現的視圖腳本),那么在 someAction() 中將不會呈現任何視圖腳本.
Calling _forward at any point in that progression will cause the following steps to not be executed. So if you call _forward in preDispatch(), someAction() will not be called and so on. If you _forward() in someAction() and you are using the viewRenderer action helper to render your views (you are letting the framework choose what view script to render), then no view script will be rendered in someAction().
當請求被轉發到新的控制器/模塊時,整個調度過程將在那里重復.
When the request is forwarded to the new Controller / Module the entire dispatch process will be repeated there.
您可以使用以下方法找出正在調度的操作:
You can find out what action is being dispatched by using:
$action = $this->getRequest()->getParam('action');
$action 將是動作的 url 形式,因此如果方法名稱為someKindOfAction",則 $action 將包含some-kind-of".您也可以對控制器和模塊執行此操作.
$action will be the url form of the action so if the method is name 'someKindOfAction', $action will contain 'some-kind-of'. You can do this as well for controllers and modules.
這篇關于Zend 框架,$this->_forward 在做什么的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!