<?php
namespace App\Controller\Admin01;

/**
 * Roles Controller
 *
 * @property \App\Model\Table\RolesTable $Roles
 *
 * @method \App\Model\Entity\Role[]|\Cake\Datasource\ResultSetInterface paginate($object = null, array $settings = [])
 */
class RolesController extends AppController
{

    public function index(){
        
        $this->Crud->on('beforePaginate', function (\Cake\Event\Event $event) {
            $event->subject->query->contain(['Modules']);
        });
        
        return $this->Crud->execute();
    }
    
    public function add(){
                
        $modules = $this->Roles->Modules->find('list');

        $this->set(compact('role', 'modules'));
        $this->set('_serialize', ['role']);
        
        return $this->Crud->execute();
           
    }
    
    public function edit($id = null){
        
        $this->Crud->on('beforeFind', function (\Cake\Event\Event $event) {
            $event->subject->query->contain(['Modules']);
        });
        
        $modules = $this->Roles->Modules->find('list');

        $this->set(compact('role', 'modules'));
        $this->set('_serialize', ['role']);
        
        return $this->Crud->execute();
           
    }
}
