Question

I am not sure if I formulated the question right, but still ...

I have a view that shows a flash embed and this flash take as parameter a /controller/action URL that generates a XML. I nee to send, from this view, an array to the XML generator action. How is the best way ? Is there some helper->set() method like or I have to create an specific URL to send this array to that action ?

Here goes my structure:

my_controller.php

function player() {}

player.ctp

<div id="myDiv">Here it Goes</div>
<script type="text/javascript">
  var so = new SWFObject('player.swf','test','50','50','8');
  so.addVariable('file','/xml/generate'); // need to pass an array here
  so.write('myDiv');
</script>

xml_controller.php

public function generate() {
  // I need to read an array here
}

generate.ctp

echo "<xml><data>" . $array['contents'] . "</data>";
Was it helpful?

Solution

First of all you cannot send data from one view to another in the manner you are speaking. Each of those calls would be a separate request and this means that it goes out of the framework and then in again. This means that the framework will be built and tear down between calls, making impossible to pass the data between views.

Now in regards to the array that has to be sent to your action, I'm utterly confused. I don't think you are looking at the problem the right way. If that action needs an array of data and then produce XML so the Flash Object can get it, then it makes even less sense. Are you sure that the Flash Object isn't the one responsible to sending that array of data to the Param you mentioned?

Well, even if all you are saying has to be done quite like that, I'll suggest you drop that array on the file system and then pick it up when the action is called by the Flash.

Or another suggestion would be to use AJAX to send that array to the action.

Both suggestions imply my utter "cluelessness" on your predicate.

I still have to ask, isn't the Flash Object gonna do something in all this?

OTHER TIPS

If the array is small enough, serialize then urlencode it and add it as a paramter to the url to your generate action:

player.ctp

so.addVariable('file','/xml/generate/<?php echo urlencode(serialize($array)); ?>');

then read it back:

public function generate($array) {
  $array = unserialize($array);
}

Save the array in the session then in the next request to the XML generator action, read it back from the session.

my_controller.php

function player() {
  $this->Session->write('key', $array);
}

xml_controller.php

public function generate() {
  $array = $this->Session->read('key');
}

However, I have heard of some problems where flash sometimes doesn't send session cookies, in which case, append the session id to the url of the action:

so.addVariable('file','/xml/generate/<?php echo $session->id(); ?>');

and to get the session back:

public function generate($sessionId) {
  CakeSession::id($sessionId);
  $array = $this->Session->read('key');
}

You can send an array with data from a view to a controller in CakePHP like this.

To the link you can pass arguments:

www.site.com/model/action/param1:foo/param2:test

You can then retrieve them in the controller action in the following way:

$yourarray = $this->params['named'];

Of course the array shouldn't be too large then.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top