OXID models: Getting, updating and storing database data

The OXID eShop architecture is based on MVC patterns. To implement models, active record pattern is used. So in general, each model class is linked with a database table. For example, the oxArticle model is linked with the oxarticles table, oxorder with the oxorders table etc. All models are stored in the directory application/models (from OXID eShop v.5.0 and 4.7 on). Let’s take one of them, for example the oxArticle model, and try to fetch the product (with the ID ‘demoId’) data from database.

Magic getters are used to get models attributes; they are constructed in this approach:

  • ‘tablename’ is the name of the database table where the model data is stored
  • ‘columnname’ is the name of the column of this table containing the data you want to fetch

To set data to a model and store it, database magic setters (with the same approach as magic getters) are used:

In this example the new record will be inserted into the table. To update an information, we have to load the model, set the new data and call the save()-method:

There are other ways to do the same – without loading the data – just simply setting the ID with the setId()-method:

In this example, it will be checked if this ID exists and if so, the record in the database will be updated with the new record.


5.00 avg. rating (93% score) - 3 votes

1 reply

Trackbacks & Pingbacks

  1. […] Quelle: Tutorials/Getting, updating and storing database data […]

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *