I have problem when save result select data options from other tables.
below this orm hasMany
table usertraces hasMany signs
table userTraces
+-----+------------+------------+
+ ID + Username + sign +
+-----+------------+------------+
+ 1 + John + swollen +
+ 2 + John + bloody +
+-----+------------+------------+
table signs
+-----+------------+
+ ID + sign +
+-----+------------+
+ 1 + swollen +
+ 2 + bloody +
+-----+------------+
method signsTable
$this->belongsTo('Usertraces', [
'foreignKey' => 'usertrace_id'
]);
method usertracesTable
$this->hasMany('Signs', [
'foreignKey' => 'usertrace_id'
]);
usertracesController
public function testkueri()
{
$usertrace = $this->Usertraces->newEntity();
$sign = $this->set('signs', $this->Usertraces->Signs->find('list'));
$usertrace->Gejala = $this->set('signs', $this->Usertraces->Signs->find('list'));
if ($this->request->is('post')) {
$usertrace = $this->Usertraces->patchEntity($usertrace, $this->request->getData());
if ($this->Usertraces->save($usertrace)) {
$this->Flash->success(__('Deteksi gejala berhasil disimpan'));
return $this->redirect(['action' => 'testkueri']);
}
$this->Flash->error(__('Deteksi gejala gagal disimpan, coba lagi'));
}
$this->set(compact('sign'));
$this->set(compact('usertrace'));
$this->set('_serialize', ['usertrace']);
}
testkueri.ctp
<?php
echo $this->Form->create($usertrace);
echo $this->Form->control('Username', array('type' => 'text'));
echo $this->Form->control('sign', array('type' => 'select', 'options' => $signs));
echo $this->Form->end();
?>
the query result populate select options was sucess work, but can’t saved in tables usertraces
table userTraces
+-----+------------+------------+
+ ID + Username + sign +
+-----+------------+------------+
+ 1 + John + null +
+ 2 + John + null +
+-----+------------+------------+
I hope someone help me fix the trouble, thanx for help…