zoukankan      html  css  js  c++  java
  • Zend Framework 跳转方法(render, forward, redirect)区别与总结 ...

    一. render(最常见的,只能在当前控制器使用,用于跳转到不同的视图)
    不指定render
    结果: {当前Module}/{当前Controller}/{当前Action}.phtml

    $this->render(‘bar’) ;
    结果: {当前Module}/{当前Controller}/bar.phtml

    二. forward(重要,主要用于不同的控制器之间跳转)

    在任意的pre/postDispatch()或者动作中调用该方法_forward(),并传入动作、控制器、模块、以及可选的附加参数,就可以进入新的动作。
    $this->_forward(‘bar’) ;
    结果: {当前Module}/{当前Controller}/bar

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

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

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

    三. redirect(用于跨域等,直接302跳转)
    $this->_redirect(‘/hoge’) ;
    结果: /hoge

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

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

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

  • 相关阅读:
    jsoncpp使用
    java学习笔记12--国际化
    java学习笔记13--比较器(Comparable、Comparator)
    java学习笔记15--引用传递
    java学习笔记16--异常
    Java学习笔记——File类之文件管理和读写操作、下载图片
    java学习笔记3
    我的二十一天CoreJava 学习笔记
    大数据处理方面的 7 个开源搜索引擎
    GridView编辑删除操作
  • 原文地址:https://www.cnblogs.com/dafa/p/2881636.html
Copyright © 2011-2022 走看看