B
B
bizzonaru2017-01-04 15:15:03
Yii
bizzonaru, 2017-01-04 15:15:03

How to redo the model -> attributes relationship in the form?

There is a standard way to bind a column from a model to a list of values ​​from another table, for the one-to-many case.

<?=
                        $form->field($model, 'id')->checkboxList(
                            \yii\helpers\ArrayHelper::map(DirectoryTypesAds::find()->all(),
                            "id",
                            "name"                                
                        ));
                    ?>

In order to make the many-to-many case, you need to make a separate table with a list of id of one table and id of another table. The problem is that in my particular case it is not convenient to make this table and I want to store the id list from the second table as just a string with numbers separated by commas, that is, ids="1,4,5". Accordingly, the question is how to correctly link in the above code example so that the previously saved selected values ​​​​are automatically selected later?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2017-01-04
@qonand

Storing id as a string is categorically wrong. Use many-to-many communication and don't reinvent the wheel

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question