D
D
Daniil Sidorov2020-07-02 12:34:46
PHP
Daniil Sidorov, 2020-07-02 12:34:46

Is it correct to create a table to hold one record?

Good afternoon. I am making a small widget for a Yii2 site that will display a notification at the top of the page. And I need to store the following values ​​(simplified): background color, notification text, display state (on / off).

To do this, I created the corresponding table.
5efda8843d2a2627764137.png
As a matter of fact in this table there will be always one record. To get and change the values ​​of the widget, I will have to find an entry with ID equal to 1 and then work with it:

$widget = TopBarWidget::findOne(1);
$widget->active = 0;
$widget->save();

Something tells me that this is not quite the right approach to organizing data storage. Please tell me how best to organize the storage of data of one object. Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Michael, 2020-07-02
@DaniLaFokc

You can create a separate settings table for such things:
id name value
where in the value field of type text to store the serialized value of any setting.
Yes, and there should be enough extensions.

I
Ivan Ivanov, 2020-07-02
@maksim_fix

You can take these values ​​from the config/parameters

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question