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();
            $data = $_POST;
                $appModel = new Model_Application();
                $result = $appModel->createApplication($form->getValue('name'),
                    // redirect here 
        $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?


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

EDIT OR I guess this would work:


.. 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.


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dsfb20227
    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:



        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.

    点赞 评论
  • dongqu9972
    dongqu9972 2010-01-12 16:55

    Not to over-simply, but have you considered putting it in $_SESSION, and then just reading it on the next page?

    Page 1:

    $_SESSION['foo'] = 10;

    Page 2:

    echo htmlspecialchars($_SESSION['foo']);
    点赞 评论