-
-
Save cholthi/770cca3aef29d9138d9360a7d89bd51e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function delete($id = null) | |
{ | |
use \Cake\Filesystem\File; | |
$this->request->allowMethod(['post', 'delete']); | |
$website = $this->Websites->get($id); | |
debug($website->image); | |
if ($this->Websites->delete($website)) { | |
$image = new File($website)->delete(); | |
$this->Flash->success(__('The website has been deleted.')); | |
} else { | |
$this->Flash->error(__('The website could not be deleted. Please, try again.')); | |
} | |
return $this->redirect(['action' => 'index']); | |
} | |
public function add(){ | |
$website = $this->Websites->newEntity(); | |
if ($this->request->is('post')) { | |
//$image_name = uniqid().$this->request->data['image']['name']; | |
$image_name = $this->request->data['image']['name']; | |
$image_tmp = $this->request->data['image']['tmp_name']; | |
$destination = WWW_ROOT.'img'.DS.'websites'.DS.$image_name; | |
move_uploaded_file($image_tmp, $destination); | |
$this->request->data['image'] = $image_name; | |
$website = $this->Websites->patchEntity($website, $this->request->data); | |
if ($this->Websites->save($website)) { | |
$this->Flash->success(__('Data has been saved.')); | |
return $this->redirect(['action' => 'index']); | |
} else { | |
$this->Flash->error(__(' Please, try again.')); | |
} | |
} | |
$this->set(compact('website')); | |
$this->set('_serialize', ['website']); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment