views:

66

answers:

2

In a CakePHP application, is it better to import Controllers that have access to models or the Models themselves?

A: 

definitely the models

mark
+3  A: 

You should never import controllers. Controllers are simply "hubs" that control the data flow/input-output, they don't do anything by themselves. You shouldn't have any important, unique logic or data in controllers, and hence should never have a need to import them. Controllers are also not the interface to models or anything like that. In fact, you should decouple your models from the controller as much as possible. If you're interested in the model, import the model.

deceze
For some added clarity, trying replace occurrences of "controller" with "user flow" and "model" with "data" in deceze's answer and read it again. :) "If you're interested in the data, import the data." An example of something that imports models, and not controllers, would be a CakePHP shell (specifically the `$uses` part) http://book.cakephp.org/view/110/Creating-Shells-Tasks
deizel