Sending variables from Controller into a different view


#1

I’m posting to a controller. I need to pass those variables to another view that will process the data and post those values to an outside url.

I tried this. But it didn’t work. using the code
return go(/url)
works, but passes no data. I don’t want to pass back to the original view. I want to pass this data back to another view.

I tried this but it doesn’t work.


        $data = array(
            'foo' => 'bar'
        );

        return array('travelpost', $data);

Any suggestions. If I could post to an website and redirect that post. That would be great to know. For instance. Once my controller script ends. Then instead of passing into the view I’m able to post to an outside website and have the browser redirect to that outside url. For now I have the other code, I just need to pass the variables from my controller into another view. Then from there I can manipulate with javascript and redirect the browser.

Recap. Pass $variables in an array from Controller to View.

  1. Post happens.
  2. $variables are created in controller
  3. Controller passes to a unique view that is not the same return from the original view.
  4. New view receives values.
    // I have this part down. The stuff below.
  5. Browser redirects.

Thanks.


#2

If you just redirect, your data will be gone. You have to store your data somewhere, in the session (preferable) or in cookie, so that you can access it on another page. It’s the same thing as a shopping cart.


#3

Yeah. I think i’m going to use go and then pass in a serialized variable. Then pull that serialized value out of the url, deserialize it and run the values. It would be nice to be able to pass variables from the controller and redirect them into another view. But, tis, what it tis.


#4

HTTP is stateless, so the variable doesn’t stay. You can pass values with a Get request in the URL, or send a POST request, or store the data. If sending the data with a GET request in your URL is a good idea, that depends on the data… and the amount of data.


#5

It worked to just pass the parameters from the url.