I’m not sure where I should be putting code that access a model but is shared by more than one controller
EG updateByPk.
At the moment I have it in the model as a public method. However, this is not ideal as it then creates a second version of the model to call the update ( modelname::model()->updateByPk )
My question is, where do I put this code. Or am I going about it wrong? Inserts have no overhead because I can just use $this->param to set them up and $this->save(). This makes me think I am missing something.
I have some models that are accessed by multiple controllers. For example, some sites like stack overflow have a point system; where each user gets points for activity on the site, which in turn enables certain features of the site. The models involved in this points system need to be accessed by many controllers, and often in the same way. This requires an extra layer, so that code is not duplicated in the controller classes. However the model is not the best place for this, as it extends Active Record and so comes with a lot of overhead.
I could create a library in the components folder. But this would be confusing as the classes would be directly related to the model classes.
My solution at present is to create two classes in the model folder. one named normally. The other named the same but with ‘Access’ on the end . This way the code is in a logical location and I don’t have the overhead of instantiating Active Record classes.
What I want to know is if there is a standard here I am not familiar with? Am I missing something?