Created
September 12, 2011 02:34
-
-
Save sergiopvilar/1210477 to your computer and use it in GitHub Desktop.
Controllers
This file contains 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
<?php | |
class PainelController extends AppController { | |
var $name = "Painel"; | |
var $uses = null; | |
function admin_index(){ | |
$this->loadModel('Publication'); | |
$this->set("publication", $this->Publication->find(array('uid'=>$this->Auth->User('id')))); | |
} | |
} | |
?> |
This file contains 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
<?php | |
class PublicationsController extends AppController { | |
var $name = 'Publications'; | |
var $scaffold; | |
} | |
?> |
This file contains 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
<?php | |
class UsuariosController extends AppController { | |
var $name = 'Usuarios'; | |
function admin_index() { | |
if($this->Auth->User('level')<10): | |
$this->redirect('/'); | |
endif; | |
$this->Usuario->recursive = 0; | |
$this->set('usuarios', $this->paginate()); | |
} | |
function admin_view($id = null) { | |
if($this->Auth->User('level')<10): | |
$this->redirect('/'); | |
endif; | |
if (!$id) { | |
$this->Session->setFlash('Invalid usuario', true); | |
$this->redirect(array('action' => 'index')); | |
} | |
$this->set('usuario', $this->Usuario->read(null, $id)); | |
} | |
function admin_add() { | |
if($this->Auth->User('level')<10): | |
$this->redirect('/'); | |
endif; | |
if (!empty($this->data)) { | |
$this->Usuario->create(); | |
if ($this->Usuario->save($this->data)) { | |
$this->Session->setFlash('O usuário foi cadastrado com sucesso.', 'flash_success'); | |
$this->redirect(array('action' => 'index')); | |
} else { | |
$this->Session->setFlash('O usuário não pôde ser cadastrado. Por favor, tente novamente.', 'flash_warning'); | |
} | |
} | |
} | |
function admin_edit($id = null) { | |
if($this->Auth->User('level')<10): | |
$this->redirect('/'); | |
endif; | |
if (!$id && empty($this->data)) { | |
$this->Session->setFlash('Usuário inválido', 'flash_warning'); | |
$this->redirect(array('action' => 'index')); | |
} | |
if (!empty($this->data)) { | |
if ($this->Usuario->save($this->data)) { | |
$this->Session->setFlash('O usuário foi atualizado com sucesso.', 'flash_success'); | |
$this->redirect(array('action' => 'index')); | |
} else { | |
$this->Session->setFlash('O usuário não pôde ser salvo. Por favor, tente novamente.', 'flash_error'); | |
} | |
} | |
if (empty($this->data)) { | |
$this->data = $this->Usuario->read(null, $id); | |
} | |
} | |
function admin_delete($id = null) { | |
if($this->Auth->User('level')<10): | |
$this->redirect('/'); | |
endif; | |
if (!$id) { | |
$this->Session->setFlash('ID de usuário inválida.', 'flash_warning'); | |
$this->redirect(array('action'=>'index')); | |
} | |
if ($this->Usuario->delete($id)) { | |
$this->Session->setFlash('O usuário foi excluído com sucesso.', 'flash_info'); | |
$this->redirect(array('action'=>'index')); | |
} | |
$this->Session->setFlash('O usuário não pôde ser apagado.', 'flash_error'); | |
$this->redirect(array('action' => 'index')); | |
} | |
/** | |
* Login | |
* | |
* @access public | |
*/ | |
function login() | |
{ | |
//var_dump($this->data); | |
// Aqui é tudo automagic. O Auth Component se encarrega de fazer tudo sozinho. | |
} | |
/** | |
* Logout | |
* | |
* @access public | |
*/ | |
function logout() | |
{ | |
$this->Session->setFlash(__('Sua sessão foi encerrada.', true)); // Mensagem de logout | |
$this->redirect($this->Auth->logout()); // Redireciona para tela de logout | |
} | |
function beforeFilter() { | |
parent::beforeFilter(); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment