On Sep 21, 3:01 pm, "Ananda Putra" <[EMAIL PROTECTED]> wrote:
> You did it in every method which is need the model? Well, truthfully I have the following function in my /app/config/ bootstrap.php, and I just call attachModel( array('Model1','Model2'), $this ); $this->Model1->blah(); function attachModel( $model_names, &$instance ) { if ( !is_array($model_names) ) $model_names = array($model_names); foreach ( $model_names as $model_name ){ if ( !isset($instance->{$model_name}) ){ if ( !class_exists($model_name) ){ loadModel($model_name); } if ( class_exists($model_name) ){ $instance->{$model_name} = &new $model_name(); } } } } But it is just a shortcut for the same thing. I experimented with using the ClassRegistry so that all instances of models were shared (guessing this would be less resource intensive - rather than a separate instance for each at the moment). However, my application wasn't written with this in mind, and not all functions clean up after themselves (changing model properties etc). An area that perhaps is a bit sloppy at the moment, but I'm happy with the performance. For more info on using the ClassRegistry, see http://www.thinkingphp.org/2007/01/22/how-to-properly-create-a-model-instance-manually/ The argument for not accessing models from components is that components are meant to just be more generic helper functions to controllers - if you have some common functionality (such as session, import / export, request handling) that is not application logic, then it should be in a component. As they are not meant to have application logic, they should not need to access models. However, my personal style is that the models contain as much functionality as they can, the controllers contain as little application functionality as they can (just basic CRUD, and parsing input data), and all the application logic is in a main component. This has helped my unit testing too - I still don't have any unit tests for controllers, but all of the models and components do (covering virtually all of the application logic). Not the recommended way though, so definitely take it with a grain of salt. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---