portions of it to a behavior as soon as I need to import more than the
one type of model data.
The reason for this is I needed to handle large record count imports
where there was a substantial amount of related data in the imported
csv. This processing of the imported data can be very time consuming
and I didn't want the user to sit and wait for the import to complete
as they don't need to deal with it all right away. And at times it
would exceed my timeouts if I did wait for it.
So in my controller I accept and save the imported csv file. The
controller then calls the model to import the first X (50) number of
records from the file and returns control and displays these to the
user. An entry is added to my background queue to finish the import
starting at record 51. The background queue takes place from a shell
task calling the same code in the model.
Having the import logic and decision logic in the model is easier to
access from both the Controller and the Shell Task so I don't have
duplication. It also provides a clean path for Unit Testing.
I'm a big proponent of Fat Models for these same reasons. It
simplifies testing, its accessible from multiple controllers and it
simplifies use in a shell task.
I realize that it is possible to create an instance of a Controller
from a shell task and that its possible to test code in a Controller.
However it is much simpler to use and test model code.
A simple litmus test question is how can I test this code, and can I
use it from other controllers and the shell if I needed to. That will
tell you where your code should be placed.
Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
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?hl=en
No comments:
Post a Comment