я работаю с cakephp 3.x и сталкиваюсь с некоторыми проблемами, связанными с загрузкой изображения,
, если я не загружаю какое-либо изображение, должно быть старое изображение, но его не происходит, пожалуйста, проверьте, ниже мой код
public function edit($id = null)
{
$this->viewBuilder()->layout('home-layout');
$detail = $this->Details->get($id, [
'contain' => []
]);
if ($this->request->is(['patch', 'post', 'put'])) {
if(!empty($this->request->data['img_name']['name'])){
{
$this->request->data['img_name'] = $filename;
}
$detail = $this->Details->patchEntity($detail, $this->request-
>getData());
}
if(!empty($this->request->data['img_name']['name'])){
$filename = $this->request->data['img_name']['name'];
$uploadpath ='img/';
$uploadfile = $uploadpath. $filename;
if(move_uploaded_file($this->request->data['img_name']
['tmp_name'],$uploadfile))
{
$this->request->data['img_name'] = $filename;
}
$detail = $this->Details->patchEntity($detail, $this->request-
>getData());
}
else{
$detail = $this->Details->patchEntity($detail, $this->request-
>getData());
}
if ($this->Details->save($detail)) {
$this->Flash->success(__('The detail has been saved.'));
return $this->redirect(['action' => 'index']);
$this->Flash->error(__('The detail could not be saved. Please, try
again.'));
}
$this->set(compact('detail'));
}