i need to code a app that will create widgets, this is; adding childrens to a container in runtime.
I need a way to read the code of the created widget so i can store it in a database as a string (i guess it’s the best way since afterwards using eval() may do the trick to load the stored widgets).
Thanks in advance.
No I don’t think you can do that, or extremely inefficient.
The best way would be to determine what kind of data you would need to store in order to re-create it back from simple configuration.
For example, I have a Blog system, and in it we have 4 different set of widgets, namely
TextWidget,RSSWidget,BlogRollWidget,MetaWidgetAll of these widgets inherited from a base class
Widgetand organized by a parent class calledWidgets. ThisWidgetsclass will then have the ability to read raw configuration and re-create the widgets base on thetype, as well as some other data as needed by each individual widgets.Such configuration string could be something like this:
So in a way that you have the ability to recreate different type of widgets base on the configuration, and at the same time you can simply
stringifyit and save it in your database.