Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // src/Controller/ArticlesController.php
- namespace App\Controller;
- class AlunosController extends AppController {
- public function initialize() {
- parent::initialize();
- $this->loadComponent('Flash'); // pode ser incluído no AppController
- }
- public function index() {
- $alunos = $this->Alunos->find('all');
- $this->set(compact('alunos'));
- }
- public function add() {
- $aluno = $this->Alunos->newEntity();
- if ($this->request->is('post')) {
- $aluno = $this->Alunos->patchEntity($aluno, $this->request->data);
- if ($this->Alunos->save($aluno)) {
- $this->Flash->success(__('Registro incluído com sucesso !'));
- return $this->redirect(['action' => 'index']);
- }
- $this->Flash->error(__('Erro: o registro não foi incluído !'));
- }
- $this->set('aluno', $aluno);
- }
- public function edit($id = null) {
- $aluno = $this->Alunos->get($id);
- if ($this->request->is(['post', 'put'])) {
- $this->Alunos->patchEntity($aluno, $this->request->data);
- if ($this->Alunos->save($aluno)) {
- $this->Flash->success(__('Registro atualizado com sucesso !'));
- return $this->redirect(['action' => 'index']);
- }
- $this->Flash->error(__('Erro: o registro não foi modificado !'));
- }
- $this->set('aluno', $aluno);
- }
- public function remove($id) {
- $this->request->allowMethod(['post', 'delete']);
- $aluno = $this->Alunos->get($id);
- if ($this->Alunos->delete($aluno)) {
- $this->Flash->success(__('O aluno(a) {0} foi removido(a).', h($aluno->nome)));
- return $this->redirect(['action' => 'index']);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement