Created
January 8, 2012 01:24
-
-
Save patrickmaciel/1576736 to your computer and use it in GitHub Desktop.
Não está salvando aros, acos e/ou aros_acos
This file contains hidden or 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 | |
App::uses('Controller', 'Controller'); | |
class AppController extends Controller { | |
public $helpers = array('Session', 'Html', 'Form'); | |
public $components = array( | |
'Session', | |
'Acl', | |
'Auth' => array( | |
'authenticate' => array( | |
'Form' => array( | |
'fields' => array('username' => 'usuario', 'password' => 'senha'), | |
'userModel' => 'Usuario' | |
) | |
), | |
'loginAction' => array('controller' => 'usuarios', 'action' => 'login'), | |
'logoutAction' => array('controller' => 'usuarios', 'action' => 'logout'), | |
'authError' => 'Você não tem permissão para acessar esta página.', | |
'authorize' => array( | |
'Actions' => array('actionPath' => 'controllers') | |
) | |
) | |
); | |
public function beforeFilter() { | |
$this->Auth->allow('*'); | |
} | |
} |
This file contains hidden or 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 | |
App::uses('AppModel', 'Model'); | |
/** | |
* Grupo Model | |
* | |
* @property Usuario $Usuario | |
*/ | |
class Grupo extends AppModel { | |
public $useTable = 'grupos'; | |
public $displayField = 'nome'; | |
public $actAs = array( | |
'Acl' => array('type' => 'requester') | |
); | |
/** | |
* Validation rules | |
* | |
* @var array | |
*/ | |
public $validate = array( | |
'nome' => array( | |
'notempty' => array( | |
'rule' => array('notempty'), | |
//'message' => 'Your custom message here', | |
//'allowEmpty' => false, | |
//'required' => false, | |
//'last' => false, // Stop validation after this rule | |
//'on' => 'create', // Limit validation to 'create' or 'update' operations | |
), | |
), | |
'ativo' => array( | |
'boolean' => array( | |
'rule' => array('boolean'), | |
//'message' => 'Your custom message here', | |
//'allowEmpty' => false, | |
//'required' => false, | |
//'last' => false, // Stop validation after this rule | |
//'on' => 'create', // Limit validation to 'create' or 'update' operations | |
), | |
), | |
); | |
//The Associations below have been created with all possible keys, those that are not needed can be removed | |
/** | |
* hasMany associations | |
* | |
* @var array | |
*/ | |
public $hasMany = array( | |
'Usuario' => array( | |
'className' => 'Usuario', | |
'foreignKey' => 'grupo_id', | |
'dependent' => false, | |
'conditions' => '', | |
'fields' => '', | |
'order' => '', | |
'limit' => '', | |
'offset' => '', | |
'exclusive' => '', | |
'finderQuery' => '', | |
'counterQuery' => '' | |
) | |
); | |
public function parentNode() { | |
return null; | |
} | |
} |
This file contains hidden or 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 | |
App::uses('AppController', 'Controller'); | |
/** | |
* Grupos Controller | |
* | |
* @property Grupo $Grupo | |
*/ | |
class GruposController extends AppController { | |
public $uses = array('Grupo'); | |
/** | |
* index method | |
* | |
* @return void | |
*/ | |
public function index() { | |
$this->Grupo->recursive = 0; | |
$this->set('grupos', $this->paginate()); | |
} | |
/** | |
* view method | |
* | |
* @param string $id | |
* @return void | |
*/ | |
public function view($id = null) { | |
$this->Grupo->id = $id; | |
if (!$this->Grupo->exists()) { | |
throw new NotFoundException(__('Invalid grupo')); | |
} | |
$this->set('grupo', $this->Grupo->read(null, $id)); | |
} | |
/** | |
* add method | |
* | |
* @return void | |
*/ | |
public function add() { | |
if ($this->request->is('post')) { | |
$this->Grupo->create(); | |
if ($this->Grupo->save($this->request->data)) { | |
$this->Session->setFlash(__('The grupo has been saved')); | |
$this->redirect(array('action' => 'index')); | |
} else { | |
$this->Session->setFlash(__('The grupo could not be saved. Please, try again.')); | |
} | |
} | |
} | |
/** | |
* edit method | |
* | |
* @param string $id | |
* @return void | |
*/ | |
public function edit($id = null) { | |
$this->Grupo->id = $id; | |
if (!$this->Grupo->exists()) { | |
throw new NotFoundException(__('Invalid grupo')); | |
} | |
if ($this->request->is('post') || $this->request->is('put')) { | |
if ($this->Grupo->save($this->request->data)) { | |
$this->Session->setFlash(__('The grupo has been saved')); | |
$this->redirect(array('action' => 'index')); | |
} else { | |
$this->Session->setFlash(__('The grupo could not be saved. Please, try again.')); | |
} | |
} else { | |
$this->request->data = $this->Grupo->read(null, $id); | |
} | |
} | |
/** | |
* delete method | |
* | |
* @param string $id | |
* @return void | |
*/ | |
public function delete($id = null) { | |
if (!$this->request->is('post')) { | |
throw new MethodNotAllowedException(); | |
} | |
$this->Grupo->id = $id; | |
if (!$this->Grupo->exists()) { | |
throw new NotFoundException(__('Invalid grupo')); | |
} | |
if ($this->Grupo->delete()) { | |
$this->Session->setFlash(__('Grupo deleted')); | |
$this->redirect(array('action' => 'index')); | |
} | |
$this->Session->setFlash(__('Grupo was not deleted')); | |
$this->redirect(array('action' => 'index')); | |
} | |
} |
This file contains hidden or 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 | |
App::uses('AppModel', 'Model'); | |
App::uses('AuthComponent', 'Controller/Component'); | |
/** | |
* Usuario Model | |
* | |
* @property Grupo $Grupo | |
*/ | |
class Usuario extends AppModel { | |
public $useTable = 'usuarios'; | |
public $displayField = 'nome'; | |
public $actAs = array( | |
'Acl' => array('type' => 'requester') | |
); | |
/** | |
* Validation rules | |
* | |
* @var array | |
*/ | |
public $validate = array( | |
'grupo_id' => array( | |
'numeric' => array( | |
'rule' => array('numeric'), | |
//'message' => 'Your custom message here', | |
//'allowEmpty' => false, | |
//'required' => false, | |
//'last' => false, // Stop validation after this rule | |
//'on' => 'create', // Limit validation to 'create' or 'update' operations | |
), | |
), | |
'ativo' => array( | |
'boolean' => array( | |
'rule' => array('boolean'), | |
//'message' => 'Your custom message here', | |
//'allowEmpty' => false, | |
//'required' => false, | |
//'last' => false, // Stop validation after this rule | |
//'on' => 'create', // Limit validation to 'create' or 'update' operations | |
), | |
), | |
); | |
//The Associations below have been created with all possible keys, those that are not needed can be removed | |
/** | |
* belongsTo associations | |
* | |
* @var array | |
*/ | |
public $belongsTo = array( | |
'Grupo' => array( | |
'className' => 'Grupo', | |
'foreignKey' => 'grupo_id', | |
'conditions' => '', | |
'fields' => '', | |
'order' => '' | |
) | |
); | |
public function beforeSave() { | |
if(!empty($this->data['Usuario']['senha'])) { | |
$senha = $this->data['Usuario']['senha']; | |
$senha = AuthComponent::password($senha); | |
$this->data['Usuario']['senha'] = $senha; | |
} | |
return parent::beforeSave(); | |
} | |
public function parentNode() { | |
if(!$this->id && empty($this->data)) { | |
return null; | |
} | |
if(isset($this->data['Usuario']['grupo_id'])) { | |
$grupoID = $this->data['Usuario']['grupo_id']; | |
} else { | |
$grupoID = $this->field('grupo_id'); | |
} | |
if(!$grupoID) { | |
return null; | |
} else { | |
return array('Grupo' => array('id' => $grupoID)); | |
} | |
} | |
public function bindNode($usuario) { | |
return array( | |
'model' => 'Grupo', | |
'foreign_key' => $usuario['Usuario']['grupo_id'] | |
); | |
} | |
} |
This file contains hidden or 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 | |
App::uses('AppController', 'Controller'); | |
/** | |
* Usuarios Controller | |
* | |
* @property Usuario $Usuario | |
*/ | |
class UsuariosController extends AppController { | |
public $uses = array('Usuario'); | |
public function login() { | |
if($this->request->is('post')) { | |
if($this->Auth->login()) { | |
$this->redirect($this->Auth->redirect()); | |
} else { | |
} | |
} | |
} | |
/** | |
* index method | |
* | |
* @return void | |
*/ | |
public function index() { | |
$this->Usuario->recursive = 0; | |
$this->set('usuarios', $this->paginate()); | |
} | |
/** | |
* view method | |
* | |
* @param string $id | |
* @return void | |
*/ | |
public function view($id = null) { | |
$this->Usuario->id = $id; | |
if (!$this->Usuario->exists()) { | |
throw new NotFoundException(__('Invalid usuario')); | |
} | |
$this->set('usuario', $this->Usuario->read(null, $id)); | |
} | |
/** | |
* add method | |
* | |
* @return void | |
*/ | |
public function add() { | |
if ($this->request->is('post')) { | |
$this->Usuario->create(); | |
if ($this->Usuario->save($this->request->data)) { | |
$this->Session->setFlash(__('The usuario has been saved')); | |
$this->redirect(array('action' => 'index')); | |
} else { | |
$this->Session->setFlash(__('The usuario could not be saved. Please, try again.')); | |
} | |
} | |
$grupos = $this->Usuario->Grupo->find('list'); | |
$this->set(compact('grupos')); | |
} | |
/** | |
* edit method | |
* | |
* @param string $id | |
* @return void | |
*/ | |
public function edit($id = null) { | |
$this->Usuario->id = $id; | |
if (!$this->Usuario->exists()) { | |
throw new NotFoundException(__('Invalid usuario')); | |
} | |
if ($this->request->is('post') || $this->request->is('put')) { | |
if ($this->Usuario->save($this->request->data)) { | |
$this->Session->setFlash(__('The usuario has been saved')); | |
$this->redirect(array('action' => 'index')); | |
} else { | |
$this->Session->setFlash(__('The usuario could not be saved. Please, try again.')); | |
} | |
} else { | |
$this->request->data = $this->Usuario->read(null, $id); | |
} | |
$grupos = $this->Usuario->Grupo->find('list'); | |
$this->set(compact('grupos')); | |
} | |
/** | |
* delete method | |
* | |
* @param string $id | |
* @return void | |
*/ | |
public function delete($id = null) { | |
if (!$this->request->is('post')) { | |
throw new MethodNotAllowedException(); | |
} | |
$this->Usuario->id = $id; | |
if (!$this->Usuario->exists()) { | |
throw new NotFoundException(__('Invalid usuario')); | |
} | |
if ($this->Usuario->delete()) { | |
$this->Session->setFlash(__('Usuario deleted')); | |
$this->redirect(array('action' => 'index')); | |
} | |
$this->Session->setFlash(__('Usuario was not deleted')); | |
$this->redirect(array('action' => 'index')); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment