Pass data between models during same request
I'm new to CakePHP and still unfamiliar with the API. So, please bear
with me here.
I have 5 models - 2 for an external data store, 2 for a local data
store, and 1 for the controller. I have one controller that's
directing all the activity. In the controller, I fetch the remote data
and pass control to the model. I have functions in my controller model
that perform all the data manipulation. Once complete, it sends the
data back to the controller. Now comes the tricky part for me. I'll
tell you how I want the app to behave functionally, maybe I can get
help in creating the solution to implement it.
I want the data that was passed out of the Invoice model to be saved
to the local data store. The data came from the remote source
identified in the models, InvoiceHeader and InvoiceDetail. The model,
Invoice, contains the data transformation methods. Once modified, the
data is passed back to the InvoicesController. All that work is
complete. My data array is ready to be saved locally.
But how do I accomplish this? ExternalHeader and ExternalDetail model
the local data store. How do I move the data from the Invoice models
to the External models so that it can be saved? Here's my broken
function:
protected function _saveLocal($_mergedData) {
if (!isset($this->ExternalHeader)) {
$this->loadModel('ExternalHeader');
if (!isset($this->ExternalDetail)) {
$this->loadModel('ExternalDetail');
}
}
//This part is broken.
$data = array($this->ExternalHeader => $_mergedData);
pr($data); die;
$this->ExternalHeader->create();
$this->ExternalHeader->saveAll($data);
// debug($this->ExternalHeader->validationErrors);
}
Please feel free to ask questions if something is unclear. I'm also
open to rethinking my workflow if what I'm doing is un-Cake-like or
overly complex.
Any help is appreciated.
--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home