<?php
    namespace App\Controller;

    use App\Controller\AppController;
    use Cake\ORM\Locator\LocatorAwareTrait;
    use Cake\ORM\TableRegistry;
    use Cake\ORM\Query;
    use Cake\ORM\RulesChecker;
    use Cake\ORM\Table;
    use Cake\Validation\Validator;

    class MatriculasController extends AppController
    {
        public function index()
        {   
            
            $this->paginate = ['contain' => ['Users']];
    
            $matriculas = $this->paginate($this->Matriculas);
    
            $this->set(compact('matriculas'));
        }
        public function add(){
            $add = $this->Matriculas->newEmptyEntity();
            if($this->request->is('post')){
                $add = $this->Matriculas->patchEntity($add, $this->request->getData());
                if ($this->Matriculas->save($add)){
                    $this->Flash->success(__('Dados registados com sucesso!'));
                    return $this->redirect(['action' => 'index']);
                }else{
                    $this->Flash->error(__('Erro ao registar os seus dados!'));
                }
            }
            $this->set(compact('add'));
        }
    }