3

I need some help as I seem not to be able to grasp the concept.

In a framework, namely Yii, we create models that correspond to database tables. We extend them from CActiveRecord.

However, if I want to create a class that will get some data from other models but then will do all the computations based on those results and do something with them... then how do I proceed?

I want to clearly divide the responsibility so I don't want put all the calculations in source db based models. Basically the idea is that it will be taking some stuff from some models and then updating another models with the results of the calculations.

What do I do?

  • Keep all the calculations in some controller and use required models? (Hesitant about this because there is a rule to keep controller slim)
  • Create a none db model and then work from there (how?)?
  • Do something else (what?)?

Thanks for any help!

1 Answer 1

3

For you to use the Yii interpretation of Model, you will have to create class, which depends on CModel. It is an abstract class, thus you will be required to implement attributeNames() method.

To use other "Models" with this new structure, you will need to inject them in constructor, or right after your custom model has been created.


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

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

Sign up to request clarification or add additional context in comments.

2 Comments

Great video resource! Will check it out. Thanks!
@RandomWhiteTrash , you can download slides here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.