|
<?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')); |
|
} |
|
|
|
} |