morning, I have problem to collect view relation hasMany.
the ORM is table diseases hasMany impacts
table diseases
+---ID--+----Name------+
+ 1 + tooth ache +
table impacts
+--ID--+---Disease_id---+--------Name--------+
+ 1 + 1 + swollen gums +
+ 1 + 1 + bleeding gums +
inside my table methode is
DiseasesTable
<?php
class DiseasesTable extends Table
{
public function initialize(array $config)
{
$this->hasMany('Impacts', [
'foreignKey' => 'disease_id'
]);
}
}
?>
impacts table
<?php
class ImpactsTable extends Table
{
public function initialize(array $config)
{
$this->belongsTo('Diseases', [
'foreignKey' => 'disease_id'
]);
}
}
?>
inside DiseasesController
public function view($id = null)
{
$disease = $this->Diseases->get($id, [
'contain' => ['Impacts']
]);
$this->set('disease', $disease);
}
and the last inside (Diseases) view.ctp
<table>
<tr>
<th><?= __('Penyakit No:') ?></th>
<th><?= h($disease->ID) ?></th>
</tr>
<tr>
<th><?= __('Nama') ?></th>
<th><?= h($disease->Name) ?></th>
</tr>
<tr>
<th><?= __('ID') ?></th>
<th><?= $this->Number->format($disease->ID) ?></th>
</tr>
</table>
<?php if (!empty($disease->Impacts)): ?> //====error not shown the table is below=====//
<table cellpadding="0" cellspacing="0" id="isitabel" align="center">
<tr>
<th colspan="6"><h4>Akibat yang dialami</h4></th>
</tr>
<tr>
<th><?= __('ID') ?></th>
<th><?= __('Disease Id') ?></th>
<th><?= __('Name') ?></th>
<th colspan="2"><?= __('Aksi') ?></th>
</tr>
<?php foreach ($disease->impacts as $impacts): ?>
<tr>
<td><?= h($impacts->ID) ?></td>
<td><?= h($impacts->disease_id) ?></td>
<td><?= h($impacts->Name) ?></td>
<td><?= h($impacts->Akibat) ?></td>
<td>
<i class="fa fa-eye" style="font-size:15px;"></i> <?= $this->Html->link(__('Tampil'), ['controller' => 'Impacts', 'action' => 'view', $impacts->ID]) ?>
</td>
<td>
<i class="fa fa-pencil" style="font-size:15px;"></i><?= $this->Html->link(__('Perbarui'), ['controller' => 'Impacts', 'action' => 'edit', $impacts->ID]) ?>
</td>
</tr>
<?php endforeach; ?>
</table>
<?php endif; ?>
the problem was started code from here, result table not shown but there is not error messages
<?php if (!empty($disease->Impacts)): ?> //====error not shown the table is below=====//
......
.....
<?php endif; ?>
I hopefull that someone help me, thanx for your help…