We create a control system using yii2. I try to display data from several to one, but it returns an error not set as shown
Tables:
Case table
Columns: ref_no (primary key),case_description,case_raised_on
Evidence table
Columns: ref_no(foreign key), path, evidence_type
A case may have several evidence, and each evidence belongs to one case.
RELATIONSHIPS IN THE MODELS:
Case Model:
public function getEvidences()
{
return $this->hasMany(Evidence::className(), ['case_ref' => 'ref_no']);
}
Evidence model
public function getEvidenceType()
{
return $this->hasOne(EvidenceType::className(), ['type' => 'evidence_type']);
}
Controller
Case controller
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
In the view file
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'ref_no',
'case_description',
'raised_on',
'status',
'updated_on',
'evidences.evidence_type',
],
]) ?>
The view file returns an error not set in (evidences.evidence_type). It should display a record of all evidence related to a particular case, referred to by ref_no2
source
share