If I have a requirement, like a method that retrieves an specif model (or many) that needs to be used by many actions from many controllers.
where should I put this method?
For instance, I don’t agree to put “findRecentComments” method inside Comment ActiveRecord.
If a instantiate a new comment, this object should not know nothing about recent comments.
Because, it is a simple new entry from the database and it isn’t persisted yet inside it.
Even if it was, it should know just about itself, it is unique, it is an object that should know, retrive, manage ALL, but just about itself or another related objects
there should be a place who can manipulate these scenarios.
I can put a method like this inside the controller that managers the model that I’m needing.
So, how can I use, in Yii, a method of a controller if Im in another action from another controller?
more, in heavy applications i could have too many actions for a controller (model) and it would make the code less unreadble, and I’d have to do a refactoring because i could have a class with hundreds of code lines. (see Marting Flower)
that´s an observation that we can put in the documentation.
You can’t reuse it in other controllers or models. The findRecentComments method was a bad example about what you want to do.
I think something is wrong if you have a controller with many actions. It’s almost certain that this actions can be divided in other controllers. If you need to access this in many places, think about behaviors, helpers or components. There’s no documentation about helpers on yii, but you can user CFileHelper class as an example. It’s a simples class with only static methods.