dongshimao7115 2010-01-12 16:48
浏览 47
已采纳

在Zend Framework中使用变量重定向URL

Whats the recommended method for redirecting with variables in Zend Framework?

Lets say we have an action like this within a controller:

 public function newAction()
    {
        $form = new Form_ApplicationForm();
        if($this->_request->isPost()){
            $data = $_POST;
            if($form->isValid($data)){
                $appModel = new Model_Application();
                $result = $appModel->createApplication($form->getValue('name'),
                    $form->getValue('email'),
                    $form->getValue('comments'));
                if($result){
                    // redirect here 
                }
            }else{
                $form->populate($data);
            }
        }
        $this->view->form = $form;
    }

If i wanted to redirect to a URL where i could show something like:

"Thanks for your application, your reference is #123"

How should i perform this redirect?

something like this maybe?

$this->_redirect('/application/confirm/'.$result);

If so then how would i access the $result var?

EDIT OR I guess this would work:

$this->_redirect('/application/confirm/?id='.$result);

.. but i'm not sure if this is best practice or not?

I've seen examples where people use _forward() for their redirects but the URL never changes which creates issues with multiple submissions etc.

I've seen someone recommend gotoSimple() but i'm not sure about this. Still a ZF noob so apologies if this is obvious but I guess this is something with multiple uses for CRUD type systems anyway so would be interested to know.

Thanks

  • 写回答

2条回答 默认 最新

  • dsfb20227 2010-01-12 18:50
    关注

    A lot of options. Your controller's $this->_redirect() delegates the work to Zend_Controller_Action_Helper_Redirector. Check its documentation for all the options, and pick the one you like. Simplest ways not involving custom routes:

    $this->_redirect('/controller/action/param1/value1/param2/value2');
    

    or

    $this->_redirect(
        '/controller/action',
        array('param1' => 'value1', 'param2' => 'value2')
    );
    

    You're right in paying attention to the difference between _redirect and _forward. Forwarding means just re-routing the initial request, while _redirect really causes an HTTP redirect.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R
  • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法
  • ¥15 八路抢答器设计出现故障
  • ¥15 opencv 无法读取视频
  • ¥15 用matlab 实现通信仿真
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了
  • ¥15 python:excel数据写入多个对应word文档