bluesclues9
bluesclues9

Reputation: 121

Cakephp 2.3: How to send an array of data to an action in another controller for rendering?

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.

Upvotes: 1

Views: 1053

Answers (3)

Anubhav
Anubhav

Reputation: 1625

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

      }
    }

Upvotes: 1

XuDing
XuDing

Reputation: 2052

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

Upvotes: 0

Ella Ryan
Ella Ryan

Reputation: 1155

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

Upvotes: 0

Related Questions