Re: Pass data between models during same request
Thanks for the tip. I'll check it when I get back to the office.
Michael Stelly
mobile: +1.918.978.2000
skype: mjstelly
On Mon, May 7, 2012 at 6:11 PM, lowpass <zijn.digital@gmail.com> wrote:
Are these models associated with each other? If so, you can do
everything from within the Invoice model. That is, if Invoice is
associated with ExternalHeader, just do
$this->ExternalHeader->save(...) That way, there's no need for the
controller to load the other models.
On Wed, May 2, 2012 at 6:13 PM, esdev <mjstelly@gmail.com> wrote:
> 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
--
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
--
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