-1

I made my form:

<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;

/* @var $this yii\web\View */
/* @var $model app\models\FuelEnter */
/* @var $form ActiveForm */
?>
<div class="enterfuel">

    <?php $form = ActiveForm::begin(); ?>

        <?= $form->dropDownLst($model, Html::listData(Forms::model()->findAll(),'trans_id','id')) 
//I want to make 'name' be selected from table Transport
            ?> 
        <?= $form->field($model, 'average') ?>
        <?= $form->field($model, 'urban') ?>
        <?= $form->field($model, 'comb') ?>

        <div class="form-group">
            <?= Html::submitButton('Submit', ['class' => 'btn btn-primary']) ?>
        </div>
    <?php ActiveForm::end(); ?>

</div><!-- enterfuel -->

I want to use drop down list and select values from database. I have 2 tables Transport and fuel_usage. How to fill dropDownList from Transport column 'name' values? And save form results to Fuel_usage table giving Transport's 'id' +3 input fields?

Transport {transID, name}

and

Fuel {id,average, comb, urban}
tereško
  • 58,060
  • 25
  • 98
  • 150
Aipo
  • 1,805
  • 3
  • 23
  • 48

1 Answers1

2

Your question is about Yii2 but your codes are Yii1. So I will answer generally as you asked. before I answer you have to know one thing, DropdownList is part of view and should not be the part for fetching data. View are there for presenting Data. Do the the fetching in Model via controller and present them in views.

So to answer your question, assuming there is model for that table use that to get all data.

Note that there is no listData in Yii2 and ArrayMap::map replaces the same functionalities.If that was your question then its duplicate of How to make a drop down list in yii2?

Your question is unclear and ambiguous so I cannot go beyond this!

Community
  • 1
  • 1
Stefano Mtangoo
  • 6,017
  • 6
  • 47
  • 93