This tutorial is the 5th of many , if you do not have already read them from the start, i suggest you to start with the summary of this series.
We have in the previous tutorials creates a module with a controller, a block and its template and a connection to the database. We will now see how to go further with the database and how to better interact with magento.
model, collections, forms …
As we saw earlier to retrieve data from your database, you have to use the getModel , which takes as parameters the type of object, in the previous tutorial we defined an object type test/test in our model. So we will get this model by:
We have in the previous tutorials creates a module with a controller, a block and its template and a connection to the database. We will now see how to go further with the database and how to better interact with magento.
model, collections, forms …
As we saw earlier to retrieve data from your database, you have to use the getModel , which takes as parameters the type of object, in the previous tutorial we defined an object type test/test in our model. So we will get this model by:
Mage::getModel( 'test/test' ); With this model you can store messages and nicknames and you can retrieve an object in your database. If I want to get for example the « test » object with the identifier 2, you will do:
Now we want to retrieve all objects of this type that have been registered in our database. To do this we will use what is called a collection we will get through the method getCollection from our model.
With this collection, we can make operation on our database such as:
Now, what would you say if you put your module in a form to add phone numbers directly from the frontend and it sorts the entries by user name when viewing? anyone? Ok here we go!
To understand what i’ve made, read the comments in the code, it retrieves information on the form and saves them on base and then redirects to the index method.
|
No comments:
Post a Comment