Skip to content

Instantly share code, notes, and snippets.

@caionorder
Created September 17, 2015 14:52
Show Gist options
  • Save caionorder/74981b598d2e5bfa822d to your computer and use it in GitHub Desktop.
Save caionorder/74981b598d2e5bfa822d to your computer and use it in GitHub Desktop.
<?php
class BannersController extends BannersAppController {
public $uses = array();
public function admin_index(){
$this->layout="Adm.admin";
$this->Banner->recursive = 0;
$this->set('banners', $this->paginate());
}
public function admin_add(){
$this->layout="Adm.admin";
if ($this->request->is('post')) {
$this->request->data['Banner']['user_id'] = $this->Auth->user('id');
$file = $this->upload($this->request->data['Banner']['arquivo'],'img/banner');
if($file){
$this->request->data['Banner']['arquivo'] = $file;
$this->Banner->save($this->request->data);
$this->Session->setFlash('Banner cadastrado sucesso.','default',array('class'=>'alert alert-success'));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash('Erro tente novamente.','default',array('class'=>'alert alert-danger'));
}
}
}
public function admin_edit($id = null) {
$this->layout="Adm.admin";
$this->Banner->id = $id;
if ($this->request->is('post') || $this->request->is('put')) {
if ($this->Banner->save($this->request->data)) {
$this->Session->setFlash('Alteração salva.','default',array('class'=>'alert alert-success'));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash('Tente novamente mais tarde','default',array('class'=>'alert alert-danger'));
}
} else {
$this->request->data = $this->Banner->read(null, $id);
}
}
public function admin_delete($id = null) {
$this->layout="Adm.admin";
if (!$this->request->is('post')) {
throw new MethodNotAllowedException();
}
$this->Banner->id = $id;
if (!$this->Banner->exists()) {
throw new NotFoundException(__('Banner invalido'));
}
if ($this->Banner->delete()) {
$this->Session->setFlash('Banner excluido','default',array('class'=>'alert alert-success'));
$this->redirect(array('action' => 'index'));
}
$this->Session->setFlash('Erro, tente novamente mais tarde','default',array('class'=>'alert alert-danger'));
$this->redirect(array('action' => 'index'));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment