Simple models
Simple models are used to store unique data and differ from regular models in the following ways:
- The model class is inherited from the ModelSimple class.
- The model SQL table contains only 2 fields, key and value, where key is a string primary key and value is a text field.
- When creating a model, it is not necessary to enter key values into the table, MV does this automatically.
Otherwise, the creation of a simple model follows the principles described in the section General principles of models and is configured in the same way as described in the section Configuring a model.
class Options extends ModelSimple
{
protected $name = 'Settings';
protected $model_elements = [
['Show banner', 'enum', 'promo', ['empty_value' => 'Always',
'values_list' => [
'morning' => 'In the morning',
'evening' => 'In the evening',
'night' => 'At night'
]]],
['Date of accepting applications', 'date_time', 'work_date'],
['Price list', 'file', 'price_file'],
['Image at the top', 'image', 'top_image'],
['Image gallery', 'multi_images', 'gallery']
];
}
To run the simple model, as with a regular model, you need to:
- Create a class with dataype fields.
- Add the model class name to the config/models.php file.
- Run migration from console or admin panel.
The process of extracting data from simple models into templates is described in the section Outputting data in a template.
Previous section
Model setup