1
votes

I have a controller action that is supposed to validate the data and pass the results (array of data) to an action in another controller for further processing. I don't want to use Session Component for this as this is not considered ideal. Given that, is there any other way to pass data array to another controller/action.

I am using CakePHP 2.3.10

Because of the length of the data array, I am not sure if I could send as namedParams or Query string.

Thanks in advance.

3
The ideal (and for me correct) approach is to not redirect at all. The same action - and at some point the model layer - can process the data - directly and without more complication.mark
If I understand correctly, you should be able to use the requestAction, have a look at this answer: stackoverflow.com/a/11752642/191998Ronny vdb
requestAction should be a last resort for performance reasons. Would be useful to see some code to see if there are alternative ways to achieve the goal.Ella Ryan

3 Answers

1
votes

You can achieve this by using uses as shown in the example below:

 App::uses('AnotherController','Controller');
    class ContentsController extends AppController {

      function youAction(){
         $anotherControllerObject = new AnotherController();
         $anotherControllerObject->anotherControllerfunction($longDataArray);

      }
    }
0
votes

It sounds like the majority of what you need to do in ControllerA is validation and massaging the data. This can be handled by the Model attached to it.

If you move the logic from controllerA to a function in ModelA, you can then just cut out ControllerA by passing the data straight to ControllerB and having ControllerB access ModelA using loadModel.

For example in ControllerB:

$this->loadModel('ModelA');
$validatedData = $this->ModelA->aDataProcessingFunction($this->request->data);

//continue with second step of processing
0
votes

I have a controller action that is supposed to validate the data and pass the results (array of data) to an action in another controller for further processing.

Why not keep the further processing in Model (embrace fat model).