Comparing
#12 with
#13
Content
[...]
Design
------
The design approach involves creating the data structure to store the serialized array configurations with tags as variables that will be replaced at runtime. The rules/validators for validating the widget configuration, will also be stored serialized in a rules column. While running the widget at runtime, the rules will be validated dynamically using the yii\base\DynamicModel.
### 1. Data Structure
Create a table `tbl_widget_config` in your database with the following minimum columns. Create a model called `WidgetConfig
` for this table through gii.
~~~[...]
// Retrieve the configuration
public function runWidget($configId) {
$dbWidget = WidgetConfig::findOne($configId)
->asArray();
$widgetConfig = \yii\base\DynamicModel::validateData(
static::parseTags($dbWidget
['->config
']),
static::parseTags($dbWidget
['->rules
'])
);
// To run the widget call below
$class = $dbWidget
['->class_name
'];
$class::widget($widgetConfig->getAttributes());
}
```