Advertisement
Guest User

alunos controller

a guest
Mar 29th, 2015
739
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.71 KB | None | 0 0
  1. <?php
  2.  
  3. // src/Controller/ArticlesController.php
  4.  
  5. namespace App\Controller;
  6.  
  7. class AlunosController extends AppController {
  8.  
  9.     public function initialize() {
  10.    
  11.         parent::initialize();
  12.  
  13.         $this->loadComponent('Flash'); // pode ser incluído no AppController
  14.     }
  15.  
  16.     public function index() {
  17.    
  18.         $alunos = $this->Alunos->find('all');
  19.         $this->set(compact('alunos'));
  20.  
  21.     }
  22.    
  23.     public function add() {
  24.    
  25.         $aluno = $this->Alunos->newEntity();
  26.         if ($this->request->is('post')) {
  27.             $aluno = $this->Alunos->patchEntity($aluno, $this->request->data);
  28.             if ($this->Alunos->save($aluno)) {
  29.                 $this->Flash->success(__('Registro incluído com sucesso !'));
  30.                 return $this->redirect(['action' => 'index']);
  31.             }
  32.             $this->Flash->error(__('Erro: o registro não foi incluído !'));
  33.         }
  34.         $this->set('aluno', $aluno);
  35.     }
  36.    
  37.     public function edit($id = null) {
  38.    
  39.         $aluno = $this->Alunos->get($id);
  40.        
  41.         if ($this->request->is(['post', 'put'])) {
  42.             $this->Alunos->patchEntity($aluno, $this->request->data);
  43.             if ($this->Alunos->save($aluno)) {
  44.                 $this->Flash->success(__('Registro atualizado com sucesso !'));
  45.                 return $this->redirect(['action' => 'index']);
  46.             }
  47.             $this->Flash->error(__('Erro: o registro não foi modificado !'));
  48.         }
  49.  
  50.             $this->set('aluno', $aluno);
  51.     }
  52.    
  53.     public function remove($id) {
  54.    
  55.         $this->request->allowMethod(['post', 'delete']);
  56.  
  57.         $aluno = $this->Alunos->get($id);
  58.        
  59.         if ($this->Alunos->delete($aluno)) {
  60.             $this->Flash->success(__('O aluno(a) {0} foi removido(a).', h($aluno->nome)));
  61.             return $this->redirect(['action' => 'index']);
  62.         }
  63.     }
  64.  
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement