Yii models and no database

I need help as I can't seem to figure out the concept.

Within the framework, namely Yii

, we create models that match database tables

. We are expanding them from CActiveRecord

.

However, if I want to create a class that will receive some data from other models, but then do all the calculations based on those results and do something about it ... then how can I proceed?

I want to clearly share responsibility, so I don't want to put all calculations in original db-based models. Basically the idea is that it will take some things from some models and then update other models with the results of the calculations.

What should I do?

  • Store all calculations in some kind of controller and use the required models? (Hesitant about this because there is a rule to keep the controller thin)
  • Create no db model and then from there (how?)?
  • Do something else (what?)?

Thanks for any help!

+3


source to share


1 answer


To use Yii interpretation model, you will need to create a class that depends on CModel

. This is an abstract class, so you need to implement a method attributeNames()

.

To use other Models with this new structure, you will need to enter them in the designer or immediately after creating a custom model.




In a real MVC model, there is a layer that basically contains two sets of classes with specific responsibilities: domain business logic and data access operations. The objects that are responsible for Domain Business Logic have no idea where the information is stored or where it comes from. Or even if there is such a thing as a "database".

This video might explain a bit: https://vimeo.com/21173483

+3


source







All Articles