Zend Framework 跳轉方法(render, forward, redirect)區...

一. render(最多見的,只能在當前控制器使用,用於跳轉到不一樣的視圖)
不指定render
結果: {當前Module}/{當前Controller}/{當前Action}.phtmlhtml

$this->render(‘bar’) ;
結果: {當前Module}/{當前Controller}/bar.phtml跨域

二. forward(重要,主要用於不一樣的控制器之間跳轉)post

在任意的pre/postDispatch()或者動做中調用該方法_forward(),並傳入動做、控制器、模塊、以及可選的附加參數,就能夠進入新的動做。
$this->_forward(‘bar’) ;
結果: {當前Module}/{當前Controller}/barthis

$this->_forward(‘bar’, ‘foo’) ;
結果: {當前Module}/foo/barspa

$this->_forward(‘bar’, ‘foo’, ‘hoge’) ;
結果: hoge/foo/bar.net

$params = array(
‘a’ => ’1′,
‘b’ => ’2′
) ;
$this->_forward(‘bar’, ‘foo’, ‘hoge’, $params) ;
結果: /hoge/foo/bar/a/1/b/2code

三. redirect(用於跨域等,直接302跳轉)
$this->_redirect(‘/hoge’) ;
結果: /hogehtm

$this->_redirect(‘/hoge/foo’) ;
結果: /hoge/fooget

$this->_redirect(‘/hoge/foo/bar’) ;
結果: /hoge/foo/bario

$this->_redirect(‘http://localhost/hoge/foo/bar’) ;
結果: http://localhost/hoge/foo/bar

$this->_redirect(‘http://localhost/hoge/foo/bar?a=1&b=2′) ;
結果: http://localhost/hoge/foo/bar?a=1&b=2

四. 特殊狀況
不使用 layout
結果: $this->_helper->layout()->disableLayout() ;

不使用 view 結果: $this->_helper->viewRenderer->setNoRender()

相關文章
相關標籤/搜索