Difference between #12 and #13 of
How to store array/widget configuration to the database with config validation rules

Changes

Title unchanged

How to store array/widget configuration to the database with config validation rules

Category unchanged

Tutorials

Yii version unchanged

Tags unchanged

yii2, dynamic, model, save, widget, config, database, db, store, array

Content changed

[...]
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::find
One($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()); } ```
2 3
41 followers
Viewed: 24 744 times
Version: 2.0
Category: Tutorials
Written by: Kartik V
Last updated by: Kartik V
Created on: May 6, 2014
Last updated: 10 years ago
Update Article

Revisions

View all history