L
L
Leopandro2016-01-24 17:49:45
MySQL
Leopandro, 2016-01-24 17:49:45

How to generate a form (without a model, i.e. we don’t have a class) using attributes from the database?

I have tables (which are created by user-specified attributes) and I need to make a form to add an entry to this table, how can I implement this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Valera Karmanov, 2016-01-24
@motokraft

What is your difficulty? Do not know how to create a form or do not know how to write to the database??

N
Nikita, 2016-01-24
@bitver

In addition to the tables themselves, you need to create in a separate table a record about which table does what and what it is, for all this a parser / factory for creating a dynamic model is written, which you pass to the view, and there is something like

foreach($model->attributes as $attr) {
 .... // Ваши поля формы
}

The second option involves writing a similar parser, but already SCHEMA tables, not the best solution, IMHO.
Info about dynamic models:
www.yiiframework.com/doc-2.0/guide-input-validatio...
www.yiiframework.com/doc-2.0/yii-base-dynamicmodel.html
PS Most likely you will have to inherit DM and add work with DB for convenience (you can peek at ActiveRecord)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question