Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Help needed
 
mateis
Jr. Member
 
Total Posts:  24
Joined:  2008-06-09
 

Hello. The Magento system seems very complicated in the beggining. I am trying to do a simple task like adding a new entity to the system, to be able to make CRUD operations on it in the admin , and display them on the frontend. I have a created my table in the database , but it’s very unclear what to do next. I created a new module, registered it in the various xml files, but now i’m stuck on the following:

The model part:
1. I need to create a model . It’s unclear to me what class to extend: Mage_Core_Model_Abstract or Mage_Core_Model_Mysql4_Abstract? what is the difference between them ? What methods do i need to implement in my model class in order to make it work (initialization stuff...) ? How does the system make the connection between the model class and the database table ? is there a name convetion or an XML setting ? I come from a background of using ORM’s, but here it seems that there is not a direct corelation between the model classes and the database tables.
2. What are model resources ?
3. How do i use collections ? I mean i want to create a method in my model class that will do a query based on some parameters and will return a collection object (in the magento sense) that i can use to feed a grid in the admin .

The controller part:
4. How do i map a view to the current action ?
5. How do i pass parameters from the request to the view or to the model ? Which is the preffered way to do ? load the model in the controller and pass it to the view ? or load the model directly in the view ?
The view part:
5. How do i pass parameters from request to the view ? i mean i saw that i can read values from request in the controller, how do they get to the view ?

Sorry for the long post, but i really can’t find anywhere some documentation about this stuff which is really basic for a developer to be able to use this platform , and i am sure this basic info would be very good for other people starting with magento.  I would really appreciate if someone would take the time and respond to my questions, which i am sure other other people are facing too. Thank you .

 
Magento Community Magento Community
Magento Community
Magento Community
 
mateis
Jr. Member
 
Total Posts:  24
Joined:  2008-06-09
 

No one has the answer to such basic questions ?  confused

 
Magento Community Magento Community
Magento Community
Magento Community
 
crius
Guru
 
Avatar
Total Posts:  623
Joined:  2007-10-16
Denmark
 

This is also where I am stuck in extending Magento. Apparently no one knows how to make anything that requires a db model and there is no documentation for it.

 
Magento Community Magento Community
Magento Community
Magento Community
 
mateis
Jr. Member
 
Total Posts:  24
Joined:  2008-06-09
 

I really hope someone will take some time to give these answers, which i think are essential for any developer wanting to do a little more than changing the design or implementing some payment module

 
Magento Community Magento Community
Magento Community
Magento Community
 
mateis
Jr. Member
 
Total Posts:  24
Joined:  2008-06-09
 

Pretty please , with cherry on top , help us understand this system . after all, isn’t this all opensource is about ? sharing information with developers around the world with the purpose of building better software ?

 
Magento Community Magento Community
Magento Community
Magento Community
 
crius
Guru
 
Avatar
Total Posts:  623
Joined:  2007-10-16
Denmark
 

Okay, I have been digging into the Magento code, and have discovered a little about how models and resources work.

Basically, the models are the classes in the Model folders (extending Mage_Core_Model_Abstract). Simple enough. The classes in the Model/Mysql4 folders are the resources (extending Mage_Core_Model_Mysql4_Abstract), which are the links between the models and the database. So, to create a database driven model, you need a Model class and a Mysql4 class.

I was wondering where all the properties and getters/setters were. For example, I noticed a call to $_category->getName(), but the Category model don’t have a getName function! I followed the inheritance chain, and found some magic in Varien_Object. This object stores all the properties in an array $_data and then uses a special function __call to handle get and set. When PHP fails to find getName, it will invoke __call instead, and __call will look at the function name and get the corresponding attribute in the $_data array.

So, when making a model, you don’t need to specify all the attributes in the class. You just have to define the table name and id field, and Magento will take care of the rest.

 
Magento Community Magento Community
Magento Community
Magento Community
 
uni-man
Member
 
Total Posts:  34
Joined:  2008-04-04
 

@anders
have you seen http://www.magentocommerce.com/wiki/custom_module_with_custom_database_table
?

 
Magento Community Magento Community
Magento Community
Magento Community
 
crius
Guru
 
Avatar
Total Posts:  623
Joined:  2007-10-16
Denmark
 

Yeah, alistek has made the documentation we so desperately needed. Great work by alistek.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top