0
내 ActiveDataForm에 대한 소스로 ActiveDataProvider를 사용하려고합니다. 그러나 정보에 액세스 할 수 없습니다. 보기 또는 컨트롤러 내에서가 아닙니다. 어떻게 diseaseList + ListView가 작동하는지.yii2 ActiveForm과 ActiveDataProvider?
어디서 잘못되었는지 알 수 없습니다. 이렇게 질병을 앓은 경우에도 :
$disease = new Disease();
$disease = Disease::find()->where(['id'=>1]);
데이터에 액세스 할 수 없습니다. 컨트롤러에서 NEW 질병을 시작할 때만 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(); ?>
내가 받고있어 오류입니다.
$disease = Disease::find()->where(['id'=>1]);
이되어야한다 :
$disease = Disease::find()->where(['id'=>1])->one();
알고이 오류받을 이유는, ActiveForm
$disease = Disease::find()->where(['id'=>1])
에 의해 당신은 ActiveQuery
전달됩니다
감사합니다. 아침에 이것을 시도 할 것입니다! – Wijnand
안녕하세요.) –
이 문제가 해결되었습니다. 나는 또한 Yii2의 가장 중요한 요소를 읽기 시작하기 위해 내 연사로부터 조언을 받았다. 그는 이전에 그렇게했다면이 모든 질문은 존재하지 않았을 것이라고 말했다. 당신의 도움을 주셔서 감사합니다! – Wijnand