good night, and enjoy with coffee.
I have trouble while saving Users table.
The messages was successfull to save, but display in index, there’s one or more fields didn’t saved.
I have used relation
Country hasMany Users
Province hasMany Users
below this sample UsersController
public function add()
{
$user = $this->Users->newEntity();
$user->Dibuat = (Time::now())->i18nFormat('dd-MM-yyyy HH:mm:ss');
if ($this->request->is('post')) {
$user = $this->Users->patchEntity($user, $this->request->getData());
if ($this->Users->save($user)) {
$this->Flash->success(__('Pengguna berhasil ditambahkan.'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('Pengguna gagal ditambahkan, atau ada input yang sama, atau ada input yang salah, atau ada input yang kosong, atau administrator lebih dari 2 coba lagi.'));
}
$countries = $this->Users->Countries->find('list', ['limit' => 200]);
$provinces = $this->Users->Provinces->find('list', ['limit' => 200]);
}
and this model table countries, Provinces and users
UsersTable.php
$this->belongsTo('Countries', [
'foreignKey' => 'countrie_id',
]);
$this->belongsTo('Provinces', [
'foreignKey' => 'province_id',
]);
CountriesTable.php
$this->hasMany('Users', [
'foreignKey' => 'countrie_id'
]);
ProvincesTable.php
$this->hasMany('Users', [
'foreignKey' => 'province_id',
]);
and this below isnide entity
User.php
protected $_accessible = [
'Nama' => true,
'Whatsapp' => true,
'Email' => true,
'Password' => true,
'Role' => true,
'Approvesuplier' => true,
'photo' => true,
'photo_dir' => true,
'photo_size' => true,
'photo_type' => true,
'countrie_id' => true,
'province_id' => true,
];
Country.php
protected $_accessible = [
'Negara' => true,
'provinces' => true,
'users' => true,
];
Province.php
protected $_accessible = [
'countrie_id' => true,
'Provinsi' => true,
'country' => true,
'users' => true,
];
and below this inside users template add.ctp
<?php
echo $this->Form->create($user, array('type' => 'file'))."\n"; //I used for upload user avatar
echo "Negara".$this->Form->control('countrie_id', array('type' => 'select', 'id' => 'jqueryNegara', 'label' => false, 'multiple' => false, 'disabled' => 'disabled', 'class' => 'red', 'options' => $countries, 'empty' => true, 'style' => 'width:200px;'))."\n"; //this normal works and display country with select options
echo "Provinsi".$this->Form->control('province_id', array('type' => 'select', 'id' => 'jqueryProvinsi', 'label' => false, 'multiple' => false, 'disabled' => 'disabled', 'class' => 'red', 'options' => $provinces, 'empty' => true, 'style' => 'width:200px;'))."\n"; //this normal works and display province with select options
echo $this->Form->button('TAMBAH', array('type' => 'submit', 'class' => 'submit', 'id' => 'Tambah'))."\n";
echo $this->Form->end()."\n";
?>
and this below screenshoot users Template index.ctp
one and more fields success save but one and more doesn’t save
I hope someone help me, good night with coffee