MVC Duplicate Controller Functionality

I am currently looking to redesign a feature on my web application. The web application utilizes Yii (version 1) for the back-end.

In this instance I have a model and controller. The model is used to store all the userTracking data and is appropriately a userTracking model however the actual logic for the model is in a controller called UserController. I have a function called actionTrackUser($id) which is used to implement various tracking logic for a particular user and create a model for that user.

I however now need to extrapolate this functionality from the UserController to a seperate trackingController which will implement tracking for various models.

I need to be able to utilize this functionality however in the new controller and old controller. I was wondering as to the best approach for this in Yii 1 that implements MVC correctly. I thought about making a trackingModel and having the userTracking model extend that but then I would have a lot of business logic in a model in order to use it in two places.

I am fairly new to MVC and Yii so I was wondering as to the best approach to take here?

I have purposely left code out of this question as it is more a theoretical question regarding the implementation of such functionality in Yii.

Any help is appreciated.

Thanks!

hi,

the creators of yii emphasizes to keep the controller small and model fat. That means only the navigation logic should be in the controller and business logic and data retrieval in models and presentation in views.

There’s a third way. You may keep both models and controllers slim by introducing domain layer. Set of plain classes that are accepting models and doing logic with them. These could be called from controllers.

I have done that by making plain classes and accepting models and doing logic with them. These classes were saved in app\models. Do we have to create app\domains and save these? Is there any impact on system memory usage by saving them together?

Thanks,

Hari

No memory impact. You can store classes where it makes sense.