Документация InstantCMS

для администраторов и разработчиков

Инструменты пользователя

Инструменты сайта


en:dev:models:overview

Introduction

A model is an auxiliary class used by a component to add and read the data in the base. With the help of the model you can automate most frequent operations with data:

  • adding,
  • reading,
  • editing,
  • deleting,
  • filtration.

A model allows to avoid writing “empty” SQL-requests to query the database. Instead, it provides an interface (a set of methods) to work with the database entries like with standard associative arrays.

Roughly speaking, the “entry” term here and further stands for one row in some database table. Or one row from query results, when it comes to reading.

InstantCMS does not use ORM, that is why the meaning of the “model” term is somewhat different from a conventional meaning here. An InstantCMS model is not an object presentation of one entry. The model here is only an object that contains a set of methods to work with the base. In other words, one InstantCMS model can work with any entries. However, it has common features with ORM. For example, an automatic filtration of incoming data.

The model adds a level of abstraction between business logic (controller) and data storage (base). In theory, this may help to change the storage (for example, to use PostgreSQL instead of MySQL) without need to customize the controller code.

Models and Components

Each model is a logic part of some component. The model cannot exist without a component. However, the component can contain only a model.

The model undertakes all the work on data extraction and editing. Other component parts (controllers, templates) should not contain any logic related to receiving or storing the data in the base. They can only request needed data from the model or vice versa pass new data to save.

A detailed description of how to use the model inside the component is described in the proper section.

Model Class

The path to the model file is formed according to the scheme: /system/controllers/{component}/model.php. For example, the “Comments” component’s model is located in the /system/controllers/comments/model.php file.

Inside the file, the model class, whose title is formed like model{Component}, is defined; for example, modelComments. The class is inherited from the cmsModel system class:

class modelExample extends cmsModel {}

The description of how to use the object of this class is here.


Back to "Models" Section Contents


Back to Documentation Contents

en/dev/models/overview.txt · Последнее изменение: 29.03.2017 16:18 — murlysja

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki