public function edit($id = null) {
$bio = $this->Bios->get($id, [
'contain' => [],
]);
if ($this->request->is(['patch', 'post', 'put'])) {
$home_page_image = $this->request->getData('home_page_image');
$bio -> home_page_image = $home_page_image;
$bio = $this->Bios->patchEntity($bio, $this->request->getData());
if(!$bio->getErrors()) {
if (!empty($this->request->getData('resize_to_thumb'))) {
$resize_to_thumb=$this->request->getUploadedFile('resize_to_thumb');
if ($resize_to_thumb->getError() == 0) {
$destination = WWW_ROOT.'img'.DS.'bio_images'.DS.$resize_to_thumb->getClientFilename();
$fileName = $resize_to_thumb->getClientFilename();
$fileName = 'img/bio_images/' . $fileName;
$bio->resize_to_thumb=$fileName;
$resize_to_thumb->moveTo($destination);
}
}
if (!empty($this->request->getData('home_page_image'))) {
$fileName2 = $home_page_image->getClientFilename();
$destination2 = WWW_ROOT.'img'.DS.'bio_images'. DS . $fileName2;
$fileName2 = 'img/bio_images/' . $fileName2;
$bio->home_page_image=$fileName2;
$home_page_image->moveTo($destination2);
}
}
}
if ($this->Bios->save($bio)) {
$this->Flash->success(__('The bio has been saved.'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('The bio could not be saved. Please, try again.'));
}
$users = $this->Bios->Users->find('list', ['limit' => 200]);
$this->set(compact('bio', 'users'));
}