Answer the question
In order to leave comments, you need to log in
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.
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();
Answer the question
In order to leave comments, you need to log in
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.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question