yii2 ActiveDataProvider в сочетании с ActiveForm?

Я пытаюсь использовать ActiveDataProvider в качестве источника для моей ActiveDataForm.
Однако я не могу получить доступ к информации. Не изнутри зрения или контроллера. Тем не менее, как работает AIDSList + ListView.

Я не могу понять, где я ошибся. Даже когда я заболеваю так:

$disease = new Disease();
$disease = Disease::find()->where(['id'=>1]);

Я не могу получить доступ к данным. Только когда я запускаю НОВУЮ болезнь в контроллере, я могу заставить ActiveForm работать должным образом.

контроллер:

public function actionIndex($id = 1)
{
$disease = new ActiveDataProvider([
'query' => Disease::find()
->where(['id'=>$id]),
'pagination' =>  [
'pageSize' => 1,
]
]);

$diseaseList = new ActiveDataProvider([
'query' => Disease::find()->orderBy('LOWER(name)'),
'pagination' =>  [
'pageSize' => 20,
]
]);
return $this->render('index', ['disease' => $disease, 'diseaseList' => $diseaseList]);
}

По-моему:

<?php
echo ListView::widget([
'dataProvider' => $diseaseList,
'itemView' => function($diseaseList, $key, $index, $widget)
{
return
Html::a($diseaseList->name,
Url::toRoute(['disease/index', 'id' => $diseaseList->primaryKey]));
}
]);
?>

<?php
$form = ActiveForm::begin([
'id' => 'disease-form-vertical'
]);
?>
<?= $form->field($disease, 'name') ?>
<?= $form->field($disease, 'description') ?>
<?= $form->field($disease, 'transmission') ?>
<?= $form->field($disease, 'actions') ?>
<?= $form->field($disease, 'report') ?>
<?= $form->field($disease, 'exclusion') ?>
<?= $form->field($disease, 'notes') ?>
<div class="form-group">
<?= Html::submitButton('Login', ['class' => 'btn btn-primary']) ?>
<?= Html::resetButton('Reset', ['class' => 'btn btn-default']) ?>
</div>
<?php ActiveForm::end(); ?>

Вот ошибка, которую я получаю.
ошибка

0

Решение

Здесь что-то не так:

$disease = Disease::find()->where(['id'=>1]);

Которые должны быть:

$disease = Disease::find()->where(['id'=>1])->one();

Чтобы узнать, почему вы получаете эту ошибку: вы передаете ActiveQuery на ваш ActiveForm от $disease = Disease::find()->where(['id'=>1]) что неправильно. ActiveForm не принимает ActiveQuery,

1

Другие решения

Других решений пока нет …