Skip to content

Instantly share code, notes, and snippets.

@cholthi
Forked from distromob/WebsitesController.php
Last active February 22, 2017 12:34
Show Gist options
  • Save cholthi/770cca3aef29d9138d9360a7d89bd51e to your computer and use it in GitHub Desktop.
Save cholthi/770cca3aef29d9138d9360a7d89bd51e to your computer and use it in GitHub Desktop.
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