good day
I need to know how to bring data from a many-to-many relationship table to fill out a checkbox
thanks
good day
I need to know how to bring data from a many-to-many relationship table to fill out a checkbox
thanks
Hi,
the Yii Guide (Section: Working with databases) and API describes the needed tools for that very well.
Greetings
Good evening
check the documentation but I didn’t find anything about it
I found the solution as follows
in the item parameter of the checkbox an array parameter is passed where the data is stored
After that, consult the database and obtain the data, after generating the query, perform a foreach to cycle through the data and store it in the previously declared array, after that declare the variables in the action, in the update and In the form, I add the action code
<?php
$modelmecanismo = Mecanismos::find()->select('mecanismo')->where(['accidente' => $model->id])->all();
$mecanismo = [];
foreach ($modelmecanismo as $key => $mecanismos) {
$mecanismo[] = $mecanismos->mecanismo;
?>
I put this part of the code in the actionUpdate
that part is automatically generated with gii when the database is relational, it was not what I needed but thanks