views:

1961

answers:

3

Hello,

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>";
A: 

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?

Gustavo Carreno
It is just receives a URL that generates XML ... this URL is a controller's action in my case ...
Fernando Barrocal
I still don't understand how you are going to send an array to that action from outside the Flash and then it will know that it has to spit out XML when the Flash object calls it. Your name seams Spanish or Portuguese, do you want me to continue this in any of those languages?
Gustavo Carreno
I clarified my intentions :) My name is Spanish and I am Brazilian, I do speak Portuguese and English only ... My Profile have how to contact me.
Fernando Barrocal
This looks like a good question for the CakaPHP-PT Google groups: http://groups.google.com/group/cake-php-pt. Try it there and me and the gang will help you.
Gustavo Carreno
+1  A: 

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');
}
neilcrookes
+1  A: 

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);
}
neilcrookes