我试图了解为什么我的下拉列表不起作用。当我尝试运行与此模型/视图/控制器相关的自定义视图时,收到以下错误消息。
请原谅我的无知,因为我是代理人对PHP和PHP框架完全陌生。
站点控制器代码:
public function actionStudentcentrequiz()
{
$model = new GameId();
$qnamodel = new Questions();
$listData = ArrayHelper::map(Gameid::find()->all(), 'gameid','gamename');
if ($qnamodel->load(Yii::$app->request->post())) {
//PK FK relation
$model->gameid = $qnamodel->gameid;
if ($qnamodel->validate()) {
//var_dump($qnamodel); die;
//then save.
$qnamodel->save();
}
//form inputs are valid, do something here
return;
}
return $this->render('studentcentrequiz', [
'model' => $model,
'qnamodel' => $qnamodel,
'listData' => $listData,
]);
}
view / questions / _form.PHP
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model app\models\Questions */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="questions-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'Question')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'Answer1')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'Answer2')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'Answer3')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'Answer4')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'gameid')->dropDownList($listData,['prompt'=>'ChooseGameID']) ?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
view / questions / _create.PHP
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model app\models\Questions */
$this->title = 'Create Questions';
$this->params['breadcrumbs'][] = ['label' => 'Questions', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="questions-create">
<h1><?= Html::encode($this->title) ?></h1>
<?= $this->render('_form', ['model' => $model, 'listData' => $listData,
]) ?>
</div>
view / questions / _update.PHP
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model app\models\Questions */
$this->title = 'Update Questions: ' . $model->questionID;
$this->params['breadcrumbs'][] = ['label' => 'Questions', 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->questionID, 'url' => ['view', 'id' => $model->questionID]];
$this->params['breadcrumbs'][] = 'Update';
?>
<div class="questions-update">
<h1><?= Html::encode($this->title) ?></h1>
<?= $this->render('_form', ['model' => $model, 'listData' => $listData,]) ?>
</div>
答案 0 :(得分:0)
好吧,两个小时后出现同样的问题
查看:
$ form-> field($ model [0],'gameid')-> dropDownList($ listData,['prompt'=>'ChooseGameID'])
为什么?我不知道,我想向某人解释,我有41条记录,并且在下拉列表[0] [1] [2]中都以相同的方式出现...