I will edit article that containing picture of article, the record was success edit and saving., also the picture before is was success delete. But the new picture was failed to save.
code in my controller
public function edit($id = null)
{
$article = $this->Articles->get($id, [
'contain' => ['Comments', 'Tags']
]);
$article->user_id = $this->request->getSession()->read('Auth.User.ID');
$article->Diubah = (Time::now())->i18nFormat('dd-MM-yyyy HH:mm:ss');
if ($this->request->is(['patch', 'post', 'put'])) {
$article = $this->Articles->patchEntity($article, $this->request->getData());
$idgbrarticle = $this->Articles->findById($id)->firstOrFail();
$hpsgbr = new File(WWW_ROOT . '/files/Articles/photo/' . $idgbrarticle->photo);
$hpsgbr->delete();
$article->photo = $this->request->getData();
if ($this->Articles->save($article)) {
$this->Flash->success(__('Artikel berhasil diperbarui.'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('Artikel gagal diperbarui, Coba lagi.'));
}
$users = $this->Articles->Users->find('list', ['limit' => 200]);
$comments = $this->Articles->Comments->find('list', ['limit' => 200]);
$tags = $this->Articles->Tags->find('list', ['limit' => 200]);
$this->set(compact('article', 'users', 'comments', 'tags'));
}
I hope someone help me, thanx