Skip to content

Instantly share code, notes, and snippets.

@distromob
Last active February 23, 2017 08:52
Show Gist options
  • Save distromob/b882d403779518dd56348a7525edd99b to your computer and use it in GitHub Desktop.
Save distromob/b882d403779518dd56348a7525edd99b to your computer and use it in GitHub Desktop.
public function delete($id = null)
{
$this->request->allowMethod(['post', 'delete']);
$website = $this->Websites->get($id);
if ($this->Websites->delete($website)) {
$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