Take the 2-minute tour ×
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It's 100% free, no registration required.

I created a module and I have a collection model class(under Model/Mysql4/MyModule/Collection.php), resource class (Model/Mysql4/MyModule.php), abstract model class (Model/MyModule.php) and a setup class (Model/Resource/Mysql4/Setup.php).

I really created them and my module worked perfectly. But I really don't know exact differences between all those models.

I really don't know which function should I put to which file. In a dummy example, I have a function to get all categories with 3 products inside. Where should I define my function and in which model ?

share|improve this question
    
    
Thanks @FabianBlechschmidt You are somehow correct. I really know the overal differences , but currently I really don't know where to put my function? I confused with all these...What do you suggest ? Thanks for your comment and answer on that question. It was helpful. –  Miko Jul 17 at 7:36
    
well, have a file like (Model/Mymodel.php) and make it extend your abstract model. Then, define some functions there. –  Julien Lachal Jul 17 at 7:37
    
@JulienLachal Thanks for your suggestion, but why there ? I mean why not in collection model ? What will happen if I put it to wrong file ? How can I know my function related to which file here ? Thanks again. –  Miko Jul 17 at 7:38

1 Answer 1

up vote 2 down vote accepted
  • Resource collections are a list of models, everything which filters the collection, orders it or joins stuff into it belongs here.
  • resource models are the ORM (more or less), so everything which communicates with the database belongs here. getItemById(), createNewItem(), etc.
  • Model is a data container and the business logic so everything else belongs here.

But depending on the complexity of the business logic I would think about creating more models (without any extend) and helper (when the logic doesn't change any inner status)

share|improve this answer
    
That's whay I wanted to know. You are the man :) –  Miko Jul 17 at 7:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.