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()

相关文章
相关标签/搜索