In Yii2 to do a linked list with rows from database?

<div class="row">
 <div class="col-md-4 vcenter">
 <?= $form--->field($model, 'type_task_filter')->dropDownList(['city1'=>'city1','city2'=>city2'], ['prompt'=>"]); ?>
</div>
</div>
<div class="row">
 <div class="col-md-4 vcenter">
 <?= $form--->field($model, 'type_task_filter')-> ? ?>
</div>
</div>


Actually, question is: When selecting the drop-down list opens tied to it and displays the value from the cell database. For example, select 'city1' and opens(appears) a new field with the data from the cell database. I can not understand methods Yii2 it is feasible ? Could you tell me the solution, I would be very grateful.

On native php + ajax it would look like this: one file *.php: create the form create a table ask
<select id="cityvm" onchange="change_city()">
<option></option>
<?php
 $res=mysqli_query($link,"select * from cities");
 while($row=mysqli_fetch_array($res)) 
{
?>
 <option value="<?php echo $row[" id"]; ?>"><?php echo $row["name"]; ?></option>
<?php
}
?>
 </select>
Then the column to display the rows from dB, who asked

Write js:
change_city function()
{
 var xmlhttp = new XMLHttpRequest();
 xmlhttp.open("GET", "ajax.php?city="+document.getElementById("cityvm").value, false);
xmlhttp.send(null);
document.getElementById("street").innerHTML=xmlhttp.responseText;

}

And in another file ajax.php:
if($city !=""){
 $res = mysqli_query($link, "SELECT * FROM streets WHERE city_id = $city");
 while ($row = mysqli_fetch_array($res))
{
 echo "<option value="$row[id]" selected>";
 echo $row["name"];
}
}</option>

And would look like this:
ee6e9cd9da0d47988c235d0a93e2db06.jpg
August 19th 19 at 22:36
1 answer
August 19th 19 at 22:38
Catch in js change select, ajax send to the server, there are doing a sample return json (or finished view) was inserted into the DOM.

Find more questions by tags PHPYii