Is there a way to submit a form when I change a select option without using ajax and jquery?
You want the fact that an option was changed to trigger the submission of the form? That requires JavaScript of some sort. Can be jQuery, but doesn’t need to be. If you want the results to load in the same page, then that requires Ajax.
Thank you @Zuluru, I thought that would be the answer
I send the select option by ajax with jquery, in what method of AppController.php should I receive it to make the changes in the profile selected?
This is the code of navbar.php (a template located at element folder):
<?php if(!empty($userApp)){ ?>
<?= $this->Html->tag('div', $this->Html->image($userApp->professional->image_url,
['style'=>'float: left;border-radius:50%;width:90px;height:90px;margin:10px;'])
.$this->Html->tag('p', h($userApp->professional->full_name))
.$this->Html->tag('p', 'Profesión: '.h($userApp->professional->profession->name))
.$this->Html->tag('p', 'Rol: '.h($userApp->profile->name))
.$this->Html->link('Cambiar contraseña', ['controller' => 'Users', 'action' => 'changepassword', $id]), ['style' => 'margin:10px']) ?>
<?php } ?>
<?php
$controller = !empty($id) ? 'Home' : 'Users';
$action = !empty($id) ? 'index' : 'login';
$icon = !empty($userApp) ? $this->Html->tag("span", "", ['class'=>'glyphicon glyphicon-user']) :
$this->Html->link($this->Html->tag("span", "", ['class'=>'glyphicon glyphicon-user']),['controller'=>'Users','action'=>'changepassword', $id],
['escape' => false, 'title' => 'Cambiar contraseña']);
?>
<?= !empty($username) ? $this->Html->tag('span', $this->Html->link(__('Calificador CIF'),['controller'=>'Home','action'=>'index'], ['title' => 'Inicio']),
['style' => 'margin-left:10px;'])." | ".$icon." ".$username : $this->Html->link(__('Calificador CIF'),['controller'=>'Users','action'=>'login']) ?>
<?php if(!empty($username)){ ?>
<?php
$control = !empty($profiles) && $count > 1 ? $this->Html->tag('span', $this->Form->control('profile_id', ['label' => false, 'options' => $profiles,
'empty' => '- Seleccione un perfil -', 'id' => 'profile_id']), ['class' => 'float-right']) : '';
echo $this->Form->create();
echo $this->Html->tag('div', $this->Html->link('Salir', ['controller' => 'Users', 'action' => 'logout'], ['class' => 'button'])
.$control, ['class' => 'title_bar']);
echo $this->Form->end();
?>
<?php
}
if(!empty($id)){
?>
<div style="margin-left:10px;float:left">
<nav class="navbar navbar-expand-lg">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar flex-column bg-body-secondary">
<li class="nav-item dropdown dropdown-hover">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Administración
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
<li><?= !empty($checkCI1) || !empty($checkCI2) || !empty($checkCI3) || !empty($checkCI4) || !empty($checkCI5) ? $this->Html->link('Administración de Países', ['controller'=>'Countries','action'=>'index'], ['class'=>'dropdown-item']) : '' ?></li>
<li><?= !empty($checkPI1) || !empty($checkPI2) || !empty($checkPI3) || !empty($checkPI4) || !empty($checkPI5) ? $this->Html->link('Administración de Provincias', ['controller'=>'Provinces','action'=>'index'], ['class'=>'dropdown-item']) : '' ?></li>
<li><?= !empty($checkLI1) || !empty($checkLI2) || !empty($checkLI3) || !empty($checkLI4) || !empty($checkLI5) ? $this->Html->link('Administración de Localidades', ['controller'=>'Localities','action'=>'index'], ['class'=>'dropdown-item']) : '' ?></li>
<li><?= !empty($checkPaI1) || !empty($checkPaI2) || !empty($checkPaI3) || !empty($checkPaI4) || !empty($checkPaI5) ? $this->Html->link('Administración de Pacientes', ['controller'=>'Pacients','action'=>'index'], ['class'=>'dropdown-item']) : '' ?></li>
<li><?= !empty($checkPrI1) || !empty($checkPrI2) || !empty($checkPrI3) || !empty($checkPrI4) || !empty($checkPrI5) ? $this->Html->link('Administración de Profesiones', ['controller'=>'Professions','action'=>'index'], ['class'=>'dropdown-item']) : '' ?></li>
<li><?= !empty($checkProI1) || !empty($checkProI2) || !empty($checkProI3) || !empty($checkProI4) || !empty($checkProI5) ? $this->Html->link('Administración de Profesionales', ['controller'=>'Professionals','action'=>'index'], ['class'=>'dropdown-item']) : '' ?></li>
<li><?= !empty($checkTI1) || !empty($checkTI2) || !empty($checkTI3) || !empty($checkTI4) || !empty($checkTI5) ? $this->Html->link('Administración de Equipos', ['controller'=>'Teams','action'=>'index'], ['class'=>'dropdown-item']) : '' ?></li>
<li><?= !empty($checkPeI1) || !empty($checkPeI2) || !empty($checkPeI3) || !empty($checkPeI4) || !empty($checkPeI5) ? $this->Html->link('Administración de Perfiles', ['controller'=>'Profiles','action'=>'index'], ['class'=>'dropdown-item']) : '' ?></li>
<li><?= !empty($checkMI1) || !empty($checkMI2) || !empty($checkMI3) || !empty($checkMI4) || !empty($checkMI5) ? $this->Html->link('Administración de Permisos', ['controller'=>'MyPermissions','action'=>'index'], ['class'=>'dropdown-item']) : '' ?></li>
<li><?= !empty($checkUI1) || !empty($checkUI2) || !empty($checkUI3) || !empty($checkUI4) || !empty($checkUI5) ? $this->Html->link('Administración de Usuarios', ['controller'=>'Users','action'=>'index'], ['class'=>'dropdown-item']) : '' ?></li>
</ul>
</li>
</ul>
</div><!-- /.collapse -->
</nav><!-- /.container-fluid -->
</div>
<script>
$(function(){
$('#profile_id').change(function(){
$.ajax({
method:"GET",
url:"<?= $this->Url->build(['action' => $this->request->getParam('action')]) ?>",
data:{
profile_id:$(this).val()
},
success: function() {
},
headers:{
'X-CSRF-Token':$('meta[name="csrfToken"]').attr('content')
}
});
});
})
</script>
<?php } ?>
And this is the code of beforeFilter method in AppController.php:
public function beforeFilter(EventInterface $event)
{
parent::beforeFilter($event);
$session = $this->request->getSession();
$this->loadModel('MyPermissions');
$this->loadModel('Teams');
$this->loadModel('Users');
$this->loadModel('Profiles');
$id = $this->Auth->user('id');
$this->id = $id;
$this->set('id', $id);
$username = $this->Auth->user('username');
$this->username = $username;
$this->set('username', $username);
if(!empty($this->request->getQuery('profile_id'))){
debug($this->request->getQuery());
$session->write(['profile_id' => $this->request->getData('profile_id')]);
}
$profile_id = $session->check('profile_id') ? $session->consume('profile_id') : $this->Auth->user('profile_id');
$this->profile_id = $profile_id;
$professional_id = $this->Auth->user('professional_id');
$this->professional_id = $professional_id;
if(!empty($professional_id)){
$userApp = $this->Users->get($this->id, ['contain' => ['Professionals.Professions', 'Profiles' => function (Query $q) use ($profile_id){
return $q->where(['Profiles.id' => $profile_id]);
}]]);
$profiles = $this->Profiles->find('list')->join([
'ProfessionalsTeams' => ['table' => 'professionals_teams',
'type' => 'LEFT',
'conditions' => 'ProfessionalsTeams.profile_id = Profiles.id'],
'Users' => ['table' => 'users',
'type' => 'LEFT',
'conditions' => 'Users.profile_id = Profiles.id']])->where(['or' => ['Users.professional_id' => $professional_id,
'ProfessionalsTeams.professional_id' => $professional_id]])->all()->toList();
$this->set(compact('userApp', 'profiles'));
$this->set('count', count($profiles));
}
if(!empty($profile_id)){
if($profile_id==3){
$this->viewBuilder()->setLayout('professional');
$this->paginate = ['contain' => 'Pacients'];
$teams = $this->paginate($this->Teams->find('all')->matching('ProfessionalsTeams')
->where(['ProfessionalsTeams.professional_id' => $professional_id]));
$this->set(compact('teams'));
$date = new FrozenDate(date('Y-m-d'));
$this->set('date', $date);
}
$profile = $this->Profiles->get($profile_id);
$checkCA1 = $this->Acl->check($profile, 'Countries/add');
$this->set('checkCA1', $checkCA1);
$checkCA2 = $this->Acl->check($profile, 'Countries/add', 'create');
$this->set('checkCA2', $checkCA2);
$checkCD1 = $this->Acl->check($profile, 'Countries/delete');
$this->set('checkCD1', $checkCD1);
$checkCD2 = $this->Acl->check($profile, 'Countries/delete', 'delete');
$this->set('checkCD2', $checkCD2);
$checkCE1 = $this->Acl->check($profile, 'Countries/edit');
$this->set('checkCE1', $checkCE1);
$checkCE2 = $this->Acl->check($profile, 'Countries/edit', 'update');
$this->set('checkCE2', $checkCE2);
$checkCI1 = $this->Acl->check($profile, 'Countries/index');
$this->set('checkCI1', $checkCI1);
$checkCI2 = $this->Acl->check($profile, 'Countries/index', 'create');
$this->set('checkCI2', $checkCI2);
$checkCI3 = $this->Acl->check($profile, 'Countries/index', 'read');
$this->set('checkCI3', $checkCI3);
$checkCI4 = $this->Acl->check($profile, 'Countries/index', 'update');
$this->set('checkCI4', $checkCI4);
$checkCI5 = $this->Acl->check($profile, 'Countries/index', 'delete');
$this->set('checkCI5', $checkCI5);
$checkCV1 = $this->Acl->check($profile, 'Countries/view');
$this->set('checkCV1', $checkCV1);
$checkCV2 = $this->Acl->check($profile, 'Countries/view', 'create');
$this->set('checkCV2', $checkCV2);
$checkCV3 = $this->Acl->check($profile, 'Countries/view', 'read');
$this->set('checkCV3', $checkCV3);
$checkCV4 = $this->Acl->check($profile, 'Countries/view', 'update');
$this->set('checkCV4', $checkCV4);
$checkCV5 = $this->Acl->check($profile, 'Countries/view', 'delete');
$this->set('checkCV5', $checkCV5);
$checkHI1 = $this->Acl->check($profile, 'Home/index');
$this->set('checkHI1', $checkHI1);
$checkHI2 = $this->Acl->check($profile, 'Home/index', 'create');
$this->set('checkHI2', $checkHI2);
$checkHI3 = $this->Acl->check($profile, 'Home/index', 'read');
$this->set('checkHI3', $checkHI3);
$checkHI4 = $this->Acl->check($profile, 'Home/index', 'update');
$this->set('checkHI4', $checkHI4);
$checkHI5 = $this->Acl->check($profile, 'Home/index', 'delete');
$this->set('checkHI5', $checkHI5);
$checkLA1 = $this->Acl->check($profile, 'Localities/add');
$this->set('checkLA1', $checkLA1);
$checkLA2 = $this->Acl->check($profile, 'Localities/add', 'create');
$this->set('checkLA2', $checkLA2);
$checkLD1 = $this->Acl->check($profile, 'Localities/delete');
$this->set('checkLD1', $checkLD1);
$checkLD2 = $this->Acl->check($profile, 'Localities/delete', 'delete');
$this->set('checkLD2', $checkLD2);
$checkLE1 = $this->Acl->check($profile, 'Localities/edit');
$this->set('checkLE1', $checkLE1);
$checkLE2 = $this->Acl->check($profile, 'Localities/edit', 'update');
$this->set('checkLE2', $checkLE2);
$checkLI1 = $this->Acl->check($profile, 'Localities/index');
$this->set('checkLI1', $checkLI1);
$checkLI2 = $this->Acl->check($profile, 'Localities/index', 'create');
$this->set('checkLI2', $checkLI2);
$checkLI3 = $this->Acl->check($profile, 'Localities/index', 'read');
$this->set('checkLI3', $checkLI3);
$checkLI4 = $this->Acl->check($profile, 'Localities/index', 'update');
$this->set('checkLI4', $checkLI4);
$checkLI5 = $this->Acl->check($profile, 'Localities/index', 'delete');
$this->set('checkLI5', $checkLI5);
$checkLV1 = $this->Acl->check($profile, 'Localities/view');
$this->set('checkLV1', $checkLV1);
$checkLV2 = $this->Acl->check($profile, 'Localities/view', 'create');
$this->set('checkLV2', $checkLV2);
$checkLV3 = $this->Acl->check($profile, 'Localities/view', 'read');
$this->set('checkLV3', $checkLV3);
$checkLV4 = $this->Acl->check($profile, 'Localities/view', 'update');
$this->set('checkLV4', $checkLV4);
$checkLV5 = $this->Acl->check($profile, 'Localities/view', 'delete');
$this->set('checkLV5', $checkLV5);
$checkMA1 = $this->Acl->check($profile, 'MyPermissions/add');
$this->set('checkMA1', $checkMA1);
$checkMA2 = $this->Acl->check($profile, 'MyPermissions/add', 'create');
$this->set('checkMA2', $checkMA2);
$checkMD1 = $this->Acl->check($profile, 'MyPermissions/delete');
$this->set('checkMD1', $checkMD1);
$checkMD2 = $this->Acl->check($profile, 'MyPermissions/delete', 'delete');
$this->set('checkMD2', $checkMD2);
$checkME1 = $this->Acl->check($profile, 'MyPermissions/edit');
$this->set('checkME1', $checkME1);
$checkME2 = $this->Acl->check($profile, 'MyPermissions/edit', 'update');
$this->set('checkME2', $checkME2);
$checkMI1 = $this->Acl->check($profile, 'MyPermissions/index');
$this->set('checkMI1', $checkMI1);
$checkMI2 = $this->Acl->check($profile, 'MyPermissions/index', 'create');
$this->set('checkMI2', $checkMI2);
$checkMI3 = $this->Acl->check($profile, 'MyPermissions/index', 'read');
$this->set('checkMI3', $checkMI3);
$checkMI4 = $this->Acl->check($profile, 'MyPermissions/index', 'update');
$this->set('checkMI4', $checkMI4);
$checkMI5 = $this->Acl->check($profile, 'MyPermissions/index', 'delete');
$this->set('checkMI5', $checkMI5);
$checkMV1 = $this->Acl->check($profile, 'MyPermissions/view');
$this->set('checkMV1', $checkMV1);
$checkMV2 = $this->Acl->check($profile, 'MyPermissions/view', 'create');
$this->set('checkMV2', $checkMV2);
$checkMV3 = $this->Acl->check($profile, 'MyPermissions/view', 'read');
$this->set('checkMV3', $checkMV3);
$checkMV4 = $this->Acl->check($profile, 'MyPermissions/view', 'update');
$this->set('checkMV4', $checkMV4);
$checkMV5 = $this->Acl->check($profile, 'MyPermissions/view', 'delete');
$this->set('checkMV5', $checkMV5);
$checkPaA1 = $this->Acl->check($profile, 'Pacients/add');
$this->set('checkPaA1', $checkPaA1);
$checkPaA2 = $this->Acl->check($profile, 'Pacients/add', 'create');
$this->set('checkPaA2', $checkPaA2);
$checkPaD1 = $this->Acl->check($profile, 'Pacients/delete');
$this->set('checkPaD1', $checkPaD1);
$checkPaD2 = $this->Acl->check($profile, 'Pacients/delete', 'delete');
$this->set('checkPaD2', $checkPaD2);
$checkPaE1 = $this->Acl->check($profile, 'Pacients/edit');
$this->set('checkPaE1', $checkPaE1);
$checkPaE2 = $this->Acl->check($profile, 'Pacients/edit', 'update');
$this->set('checkPaE2', $checkPaE2);
$checkPaI1 = $this->Acl->check($profile, 'Pacients/index');
$this->set('checkPaI1', $checkPaI1);
$checkPaI2 = $this->Acl->check($profile, 'Pacients/index', 'create');
$this->set('checkPaI2', $checkPaI2);
$checkPaI3 = $this->Acl->check($profile, 'Pacients/index', 'read');
$this->set('checkPaI3', $checkPaI3);
$checkPaI4 = $this->Acl->check($profile, 'Pacients/index', 'update');
$this->set('checkPaI4', $checkPaI4);
$checkPaI5 = $this->Acl->check($profile, 'Pacients/index', 'delete');
$this->set('checkPaI5', $checkPaI5);
$checkPaV1 = $this->Acl->check($profile, 'Pacients/view');
$this->set('checkPaV1', $checkPaV1);
$checkPaV2 = $this->Acl->check($profile, 'Pacients/view', 'create');
$this->set('checkPaV2', $checkPaV2);
$checkPaV3 = $this->Acl->check($profile, 'Pacients/view', 'read');
$this->set('checkPaV3', $checkPaV3);
$checkPaV4 = $this->Acl->check($profile, 'Pacients/view', 'update');
$this->set('checkPaV4', $checkPaV4);
$checkPaV5 = $this->Acl->check($profile, 'Pacients/view', 'delete');
$this->set('checkPaV5', $checkPaV5);
$checkProA1 = $this->Acl->check($profile, 'Professionals/add');
$this->set('checkProA1', $checkProA1);
$checkProA2 = $this->Acl->check($profile, 'Professionals/add', 'create');
$this->set('checkProA2', $checkProA2);
$checkProD1 = $this->Acl->check($profile, 'Professionals/delete');
$this->set('checkProD1', $checkProD1);
$checkProD2 = $this->Acl->check($profile, 'Professionals/delete', 'delete');
$this->set('checkProD2', $checkProD2);
$checkProE1 = $this->Acl->check($profile, 'Professionals/edit');
$this->set('checkProE1', $checkProE1);
$checkProE2 = $this->Acl->check($profile, 'Professionals/edit', 'update');
$this->set('checkProE2', $checkProE2);
$checkProI1 = $this->Acl->check($profile, 'Professionals/index');
$this->set('checkProI1', $checkProI1);
$checkProI2 = $this->Acl->check($profile, 'Professionals/index', 'create');
$this->set('checkProI2', $checkProI2);
$checkProI3 = $this->Acl->check($profile, 'Professionals/index', 'read');
$this->set('checkProI3', $checkProI3);
$checkProI4 = $this->Acl->check($profile, 'Professionals/index', 'update');
$this->set('checkProI4', $checkProI4);
$checkProI5 = $this->Acl->check($profile, 'Professionals/index', 'delete');
$this->set('checkProI5', $checkProI5);
$checkProV1 = $this->Acl->check($profile, 'Professionals/view');
$this->set('checkProV1', $checkProV1);
$checkProV2 = $this->Acl->check($profile, 'Professionals/view', 'create');
$this->set('checkProV2', $checkProV2);
$checkProV3 = $this->Acl->check($profile, 'Professionals/view', 'read');
$this->set('checkProV3', $checkProV3);
$checkProV4 = $this->Acl->check($profile, 'Professionals/view', 'update');
$this->set('checkProV4', $checkProV4);
$checkProV5 = $this->Acl->check($profile, 'Professionals/view', 'delete');
$this->set('checkProV5', $checkProV5);
$checkPrA1 = $this->Acl->check($profile, 'Professions/add');
$this->set('checkPrA1', $checkPrA1);
$checkPrA2 = $this->Acl->check($profile, 'Professions/add', 'create');
$this->set('checkPrA2', $checkPrA2);
$checkPrD1 = $this->Acl->check($profile, 'Professions/delete');
$this->set('checkPrD1', $checkPrD1);
$checkPrD2 = $this->Acl->check($profile, 'Professions/delete', 'delete');
$this->set('checkPrD2', $checkPrD2);
$checkPrE1 = $this->Acl->check($profile, 'Professions/edit');
$this->set('checkPrE1', $checkPrE1);
$checkPrE2 = $this->Acl->check($profile, 'Professions/edit', 'update');
$this->set('checkPrE2', $checkPrE2);
$checkPrI1 = $this->Acl->check($profile, 'Professions/index');
$this->set('checkPrI1', $checkPrI1);
$checkPrI2 = $this->Acl->check($profile, 'Professions/index', 'create');
$this->set('checkPrI2', $checkPrI2);
$checkPrI3 = $this->Acl->check($profile, 'Professions/index', 'read');
$this->set('checkPrI3', $checkPrI3);
$checkPrI4 = $this->Acl->check($profile, 'Professions/index', 'update');
$this->set('checkPrI4', $checkPrI4);
$checkPrI5 = $this->Acl->check($profile, 'Professions/index', 'delete');
$this->set('checkPrI5', $checkPrI5);
$checkPrV1 = $this->Acl->check($profile, 'Professions/view');
$this->set('checkPrV1', $checkPrV1);
$checkPrV2 = $this->Acl->check($profile, 'Professions/view', 'create');
$this->set('checkPrV2', $checkPrV2);
$checkPrV3 = $this->Acl->check($profile, 'Professions/view', 'read');
$this->set('checkPrV3', $checkPrV3);
$checkPrV4 = $this->Acl->check($profile, 'Professions/view', 'update');
$this->set('checkPrV4', $checkPrV4);
$checkPrV5 = $this->Acl->check($profile, 'Professions/view', 'delete');
$this->set('checkPrV5', $checkPrV5);
$checkPeA1 = $this->Acl->check($profile, 'Profiles/add');
$this->set('checkPeA1', $checkPeA1);
$checkPeA2 = $this->Acl->check($profile, 'Profiles/add', 'create');
$this->set('checkPeA2', $checkPeA2);
$checkPeD1 = $this->Acl->check($profile, 'Profiles/delete');
$this->set('checkPeD1', $checkPeD1);
$checkPeD2 = $this->Acl->check($profile, 'Profiles/delete', 'delete');
$this->set('checkPeD2', $checkPeD2);
$checkPeE1 = $this->Acl->check($profile, 'Profiles/edit');
$this->set('checkPeE1', $checkPeE1);
$checkPeE2 = $this->Acl->check($profile, 'Profiles/edit', 'update');
$this->set('checkPeE2', $checkPeE2);
$checkPeI1 = $this->Acl->check($profile, 'Profiles/index');
$this->set('checkPeI1', $checkPeI1);
$checkPeI2 = $this->Acl->check($profile, 'Profiles/index', 'create');
$this->set('checkPeI2', $checkPeI2);
$checkPeI3 = $this->Acl->check($profile, 'Profiles/index', 'read');
$this->set('checkPeI3', $checkPeI3);
$checkPeI4 = $this->Acl->check($profile, 'Profiles/index', 'update');
$this->set('checkPeI4', $checkPeI4);
$checkPeI5 = $this->Acl->check($profile, 'Profiles/index', 'delete');
$this->set('checkPeI5', $checkPeI5);
$checkPeV1 = $this->Acl->check($profile, 'Profiles/view');
$this->set('checkPeV1', $checkPeV1);
$checkPeV2 = $this->Acl->check($profile, 'Profiles/view', 'create');
$this->set('checkPeV2', $checkPeV2);
$checkPeV3 = $this->Acl->check($profile, 'Profiles/view', 'read');
$this->set('checkPeV3', $checkPeV3);
$checkPeV4 = $this->Acl->check($profile, 'Profiles/view', 'update');
$this->set('checkPeV4', $checkPeV4);
$checkPeV5 = $this->Acl->check($profile, 'Profiles/view', 'delete');
$this->set('checkPeV5', $checkPeV5);
$checkPA1 = $this->Acl->check($profile, 'Provinces/add');
$this->set('checkPA1', $checkPA1);
$checkPA2 = $this->Acl->check($profile, 'Provinces/add', 'create');
$this->set('checkPA2', $checkPA2);
$checkPD1 = $this->Acl->check($profile, 'Provinces/delete');
$this->set('checkPD1', $checkPD1);
$checkPD2 = $this->Acl->check($profile, 'Provinces/delete', 'delete');
$this->set('checkPD2', $checkPD2);
$checkPE1 = $this->Acl->check($profile, 'Provinces/edit');
$this->set('checkPE1', $checkPE1);
$checkPE2 = $this->Acl->check($profile, 'Provinces/edit', 'update');
$this->set('checkPE2', $checkPE2);
$checkPI1 = $this->Acl->check($profile, 'Provinces/index');
$this->set('checkPI1', $checkPI1);
$checkPI2 = $this->Acl->check($profile, 'Provinces/index', 'create');
$this->set('checkPI2', $checkPI2);
$checkPI3 = $this->Acl->check($profile, 'Provinces/index', 'read');
$this->set('checkPI3', $checkPI3);
$checkPI4 = $this->Acl->check($profile, 'Provinces/index', 'update');
$this->set('checkPI4', $checkPI4);
$checkPI5 = $this->Acl->check($profile, 'Provinces/index', 'delete');
$this->set('checkPI5', $checkPI5);
$checkPV1 = $this->Acl->check($profile, 'Provinces/view');
$this->set('checkPV1', $checkPV1);
$checkPV2 = $this->Acl->check($profile, 'Provinces/view', 'create');
$this->set('checkPV2', $checkPV2);
$checkPV3 = $this->Acl->check($profile, 'Provinces/view', 'read');
$this->set('checkPV3', $checkPV3);
$checkPV4 = $this->Acl->check($profile, 'Provinces/view', 'update');
$this->set('checkPV4', $checkPV4);
$checkPV5 = $this->Acl->check($profile, 'Provinces/view', 'delete');
$this->set('checkPV5', $checkPV5);
$checkTA1 = $this->Acl->check($profile, 'Teams/add');
$this->set('checkTA1', $checkTA1);
$checkTA2 = $this->Acl->check($profile, 'Teams/add', 'create');
$this->set('checkTA2', $checkTA2);
$checkTD1 = $this->Acl->check($profile, 'Teams/delete');
$this->set('checkTD1', $checkTD1);
$checkTD2 = $this->Acl->check($profile, 'Teams/delete', 'delete');
$this->set('checkTD2', $checkTD2);
$checkTE1 = $this->Acl->check($profile, 'Teams/edit');
$this->set('checkTE1', $checkTE1);
$checkTE2 = $this->Acl->check($profile, 'Teams/edit', 'update');
$this->set('checkTE2', $checkTE2);
$checkTI1 = $this->Acl->check($profile, 'Teams/index');
$this->set('checkTI1', $checkTI1);
$checkTI2 = $this->Acl->check($profile, 'Teams/index', 'create');
$this->set('checkTI2', $checkTI2);
$checkTI3 = $this->Acl->check($profile, 'Teams/index', 'read');
$this->set('checkTI3', $checkTI3);
$checkTI4 = $this->Acl->check($profile, 'Teams/index', 'update');
$this->set('checkTI4', $checkTI4);
$checkTI5 = $this->Acl->check($profile, 'Teams/index', 'delete');
$this->set('checkTI5', $checkTI5);
$checkTV1 = $this->Acl->check($profile, 'Teams/view');
$this->set('checkTV1', $checkTV1);
$checkTV2 = $this->Acl->check($profile, 'Teams/view', 'create');
$this->set('checkTV2', $checkTV2);
$checkTV3 = $this->Acl->check($profile, 'Teams/view', 'read');
$this->set('checkTV3', $checkTV3);
$checkTV4 = $this->Acl->check($profile, 'Teams/view', 'update');
$this->set('checkTV4', $checkTV4);
$checkTV5 = $this->Acl->check($profile, 'Teams/view', 'delete');
$this->set('checkTV5', $checkTV5);
$checkUA1 = $this->Acl->check($profile, 'Users/add');
$this->set('checkUA1', $checkUA1);
$checkUA2 = $this->Acl->check($profile, 'Users/add', 'create');
$this->set('checkUA2', $checkUA2);
$checkUD1 = $this->Acl->check($profile, 'Users/delete');
$this->set('checkUD1', $checkUD1);
$checkUD2 = $this->Acl->check($profile, 'Users/delete', 'delete');
$this->set('checkUD2', $checkUD2);
$checkUE1 = $this->Acl->check($profile, 'Users/edit');
$this->set('checkUE1', $checkUE1);
$checkUE2 = $this->Acl->check($profile, 'Users/edit', 'update');
$this->set('checkUE2', $checkUE2);
$checkUI1 = $this->Acl->check($profile, 'Users/index');
$this->set('checkUI1', $checkUI1);
$checkUI2 = $this->Acl->check($profile, 'Users/index', 'create');
$this->set('checkUI2', $checkUI2);
$checkUI3 = $this->Acl->check($profile, 'Users/index', 'read');
$this->set('checkUI3', $checkUI3);
$checkUI4 = $this->Acl->check($profile, 'Users/index', 'update');
$this->set('checkUI4', $checkUI4);
$checkUI5 = $this->Acl->check($profile, 'Users/index', 'delete');
$this->set('checkUI5', $checkUI5);
$checkUV1 = $this->Acl->check($profile, 'Users/view');
$this->set('checkUV1', $checkUV1);
$checkUV2 = $this->Acl->check($profile, 'Users/view', 'create');
$this->set('checkUV2', $checkUV2);
$checkUV3 = $this->Acl->check($profile, 'Users/view', 'read');
$this->set('checkUV3', $checkUV3);
$checkUV4 = $this->Acl->check($profile, 'Users/view', 'update');
$this->set('checkUV4', $checkUV4);
$checkUV5 = $this->Acl->check($profile, 'Users/view', 'delete');
$this->set('checkUV5', $checkUV5);
}
}
You’re sending your Ajax request to ['action' => $this->request->getParam('action')]
, so that’s where the form data will go.
And what should I put to receive it in AppController.php and not in the action?
Why would you want to do that? If you don’t want that action to receive it, make a different one and point the Ajax call there instead.
Thank you @Zuluru, that’s a good idea, I blinded myself with the idea of doing it with appcontroller
What am I doing wrong? I change the select option but is not changing the profile name in the top of the page.
This is the code for action changeProfile:
public function changeProfile()
{
$session = $this->request->getSession();
$this->loadModel('MyPermissions');
$this->loadModel('Teams');
$session->write(['profile_id' => $this->request->getQuery('profile_id')]);
debug($session);
$profile_id = $session->consume('profile_id');
$this->profile_id = $profile_id;
if(!empty($this->professional_id)){
$userApp = $this->Users->get($this->id, ['contain' => ['Professionals.Professions', 'Profiles' => function (Query $q) use ($profile_id){
return $q->where(['Profiles.id' => $profile_id]);
}]]);
$profiles = $this->Users->Profiles->find('list')->join([
'ProfessionalsTeams' => ['table' => 'professionals_teams',
'type' => 'LEFT',
'conditions' => 'ProfessionalsTeams.profile_id = Profiles.id'],
'Users' => ['table' => 'users',
'type' => 'LEFT',
'conditions' => 'Users.profile_id = Profiles.id']])->where(['or' => ['Users.professional_id' => $this->professional_id,
'ProfessionalsTeams.professional_id' => $this->professional_id]])->all()->toList();
$this->set(compact('userApp', 'profiles'));
$this->set('count', count($profiles));
}
if(!empty($profile_id)){
if($profile_id==3){
$this->viewBuilder()->setLayout('professional');
$this->paginate = ['contain' => 'Pacients'];
$teams = $this->paginate($this->Teams->find('all')->matching('ProfessionalsTeams')
->where(['ProfessionalsTeams.professional_id' => $this->professional_id]));
$this->set(compact('teams'));
$date = new FrozenDate(date('Y-m-d'));
$this->set('date', $date);
}
$profile = $this->Profiles->get($profile_id);
$checkCA1 = $this->Acl->check($profile, 'Countries/add');
$this->set('checkCA1', $checkCA1);
$checkCA2 = $this->Acl->check($profile, 'Countries/add', 'create');
$this->set('checkCA2', $checkCA2);
$checkCD1 = $this->Acl->check($profile, 'Countries/delete');
$this->set('checkCD1', $checkCD1);
$checkCD2 = $this->Acl->check($profile, 'Countries/delete', 'delete');
$this->set('checkCD2', $checkCD2);
$checkCE1 = $this->Acl->check($profile, 'Countries/edit');
$this->set('checkCE1', $checkCE1);
$checkCE2 = $this->Acl->check($profile, 'Countries/edit', 'update');
$this->set('checkCE2', $checkCE2);
$checkCI1 = $this->Acl->check($profile, 'Countries/index');
$this->set('checkCI1', $checkCI1);
$checkCI2 = $this->Acl->check($profile, 'Countries/index', 'create');
$this->set('checkCI2', $checkCI2);
$checkCI3 = $this->Acl->check($profile, 'Countries/index', 'read');
$this->set('checkCI3', $checkCI3);
$checkCI4 = $this->Acl->check($profile, 'Countries/index', 'update');
$this->set('checkCI4', $checkCI4);
$checkCI5 = $this->Acl->check($profile, 'Countries/index', 'delete');
$this->set('checkCI5', $checkCI5);
$checkCV1 = $this->Acl->check($profile, 'Countries/view');
$this->set('checkCV1', $checkCV1);
$checkCV2 = $this->Acl->check($profile, 'Countries/view', 'create');
$this->set('checkCV2', $checkCV2);
$checkCV3 = $this->Acl->check($profile, 'Countries/view', 'read');
$this->set('checkCV3', $checkCV3);
$checkCV4 = $this->Acl->check($profile, 'Countries/view', 'update');
$this->set('checkCV4', $checkCV4);
$checkCV5 = $this->Acl->check($profile, 'Countries/view', 'delete');
$this->set('checkCV5', $checkCV5);
$checkHI1 = $this->Acl->check($profile, 'Home/index');
$this->set('checkHI1', $checkHI1);
$checkHI2 = $this->Acl->check($profile, 'Home/index', 'create');
$this->set('checkHI2', $checkHI2);
$checkHI3 = $this->Acl->check($profile, 'Home/index', 'read');
$this->set('checkHI3', $checkHI3);
$checkHI4 = $this->Acl->check($profile, 'Home/index', 'update');
$this->set('checkHI4', $checkHI4);
$checkHI5 = $this->Acl->check($profile, 'Home/index', 'delete');
$this->set('checkHI5', $checkHI5);
$checkLA1 = $this->Acl->check($profile, 'Localities/add');
$this->set('checkLA1', $checkLA1);
$checkLA2 = $this->Acl->check($profile, 'Localities/add', 'create');
$this->set('checkLA2', $checkLA2);
$checkLD1 = $this->Acl->check($profile, 'Localities/delete');
$this->set('checkLD1', $checkLD1);
$checkLD2 = $this->Acl->check($profile, 'Localities/delete', 'delete');
$this->set('checkLD2', $checkLD2);
$checkLE1 = $this->Acl->check($profile, 'Localities/edit');
$this->set('checkLE1', $checkLE1);
$checkLE2 = $this->Acl->check($profile, 'Localities/edit', 'update');
$this->set('checkLE2', $checkLE2);
$checkLI1 = $this->Acl->check($profile, 'Localities/index');
$this->set('checkLI1', $checkLI1);
$checkLI2 = $this->Acl->check($profile, 'Localities/index', 'create');
$this->set('checkLI2', $checkLI2);
$checkLI3 = $this->Acl->check($profile, 'Localities/index', 'read');
$this->set('checkLI3', $checkLI3);
$checkLI4 = $this->Acl->check($profile, 'Localities/index', 'update');
$this->set('checkLI4', $checkLI4);
$checkLI5 = $this->Acl->check($profile, 'Localities/index', 'delete');
$this->set('checkLI5', $checkLI5);
$checkLV1 = $this->Acl->check($profile, 'Localities/view');
$this->set('checkLV1', $checkLV1);
$checkLV2 = $this->Acl->check($profile, 'Localities/view', 'create');
$this->set('checkLV2', $checkLV2);
$checkLV3 = $this->Acl->check($profile, 'Localities/view', 'read');
$this->set('checkLV3', $checkLV3);
$checkLV4 = $this->Acl->check($profile, 'Localities/view', 'update');
$this->set('checkLV4', $checkLV4);
$checkLV5 = $this->Acl->check($profile, 'Localities/view', 'delete');
$this->set('checkLV5', $checkLV5);
$checkMA1 = $this->Acl->check($profile, 'MyPermissions/add');
$this->set('checkMA1', $checkMA1);
$checkMA2 = $this->Acl->check($profile, 'MyPermissions/add', 'create');
$this->set('checkMA2', $checkMA2);
$checkMD1 = $this->Acl->check($profile, 'MyPermissions/delete');
$this->set('checkMD1', $checkMD1);
$checkMD2 = $this->Acl->check($profile, 'MyPermissions/delete', 'delete');
$this->set('checkMD2', $checkMD2);
$checkME1 = $this->Acl->check($profile, 'MyPermissions/edit');
$this->set('checkME1', $checkME1);
$checkME2 = $this->Acl->check($profile, 'MyPermissions/edit', 'update');
$this->set('checkME2', $checkME2);
$checkMI1 = $this->Acl->check($profile, 'MyPermissions/index');
$this->set('checkMI1', $checkMI1);
$checkMI2 = $this->Acl->check($profile, 'MyPermissions/index', 'create');
$this->set('checkMI2', $checkMI2);
$checkMI3 = $this->Acl->check($profile, 'MyPermissions/index', 'read');
$this->set('checkMI3', $checkMI3);
$checkMI4 = $this->Acl->check($profile, 'MyPermissions/index', 'update');
$this->set('checkMI4', $checkMI4);
$checkMI5 = $this->Acl->check($profile, 'MyPermissions/index', 'delete');
$this->set('checkMI5', $checkMI5);
$checkMV1 = $this->Acl->check($profile, 'MyPermissions/view');
$this->set('checkMV1', $checkMV1);
$checkMV2 = $this->Acl->check($profile, 'MyPermissions/view', 'create');
$this->set('checkMV2', $checkMV2);
$checkMV3 = $this->Acl->check($profile, 'MyPermissions/view', 'read');
$this->set('checkMV3', $checkMV3);
$checkMV4 = $this->Acl->check($profile, 'MyPermissions/view', 'update');
$this->set('checkMV4', $checkMV4);
$checkMV5 = $this->Acl->check($profile, 'MyPermissions/view', 'delete');
$this->set('checkMV5', $checkMV5);
$checkPaA1 = $this->Acl->check($profile, 'Pacients/add');
$this->set('checkPaA1', $checkPaA1);
$checkPaA2 = $this->Acl->check($profile, 'Pacients/add', 'create');
$this->set('checkPaA2', $checkPaA2);
$checkPaD1 = $this->Acl->check($profile, 'Pacients/delete');
$this->set('checkPaD1', $checkPaD1);
$checkPaD2 = $this->Acl->check($profile, 'Pacients/delete', 'delete');
$this->set('checkPaD2', $checkPaD2);
$checkPaE1 = $this->Acl->check($profile, 'Pacients/edit');
$this->set('checkPaE1', $checkPaE1);
$checkPaE2 = $this->Acl->check($profile, 'Pacients/edit', 'update');
$this->set('checkPaE2', $checkPaE2);
$checkPaI1 = $this->Acl->check($profile, 'Pacients/index');
$this->set('checkPaI1', $checkPaI1);
$checkPaI2 = $this->Acl->check($profile, 'Pacients/index', 'create');
$this->set('checkPaI2', $checkPaI2);
$checkPaI3 = $this->Acl->check($profile, 'Pacients/index', 'read');
$this->set('checkPaI3', $checkPaI3);
$checkPaI4 = $this->Acl->check($profile, 'Pacients/index', 'update');
$this->set('checkPaI4', $checkPaI4);
$checkPaI5 = $this->Acl->check($profile, 'Pacients/index', 'delete');
$this->set('checkPaI5', $checkPaI5);
$checkPaV1 = $this->Acl->check($profile, 'Pacients/view');
$this->set('checkPaV1', $checkPaV1);
$checkPaV2 = $this->Acl->check($profile, 'Pacients/view', 'create');
$this->set('checkPaV2', $checkPaV2);
$checkPaV3 = $this->Acl->check($profile, 'Pacients/view', 'read');
$this->set('checkPaV3', $checkPaV3);
$checkPaV4 = $this->Acl->check($profile, 'Pacients/view', 'update');
$this->set('checkPaV4', $checkPaV4);
$checkPaV5 = $this->Acl->check($profile, 'Pacients/view', 'delete');
$this->set('checkPaV5', $checkPaV5);
$checkProA1 = $this->Acl->check($profile, 'Professionals/add');
$this->set('checkProA1', $checkProA1);
$checkProA2 = $this->Acl->check($profile, 'Professionals/add', 'create');
$this->set('checkProA2', $checkProA2);
$checkProD1 = $this->Acl->check($profile, 'Professionals/delete');
$this->set('checkProD1', $checkProD1);
$checkProD2 = $this->Acl->check($profile, 'Professionals/delete', 'delete');
$this->set('checkProD2', $checkProD2);
$checkProE1 = $this->Acl->check($profile, 'Professionals/edit');
$this->set('checkProE1', $checkProE1);
$checkProE2 = $this->Acl->check($profile, 'Professionals/edit', 'update');
$this->set('checkProE2', $checkProE2);
$checkProI1 = $this->Acl->check($profile, 'Professionals/index');
$this->set('checkProI1', $checkProI1);
$checkProI2 = $this->Acl->check($profile, 'Professionals/index', 'create');
$this->set('checkProI2', $checkProI2);
$checkProI3 = $this->Acl->check($profile, 'Professionals/index', 'read');
$this->set('checkProI3', $checkProI3);
$checkProI4 = $this->Acl->check($profile, 'Professionals/index', 'update');
$this->set('checkProI4', $checkProI4);
$checkProI5 = $this->Acl->check($profile, 'Professionals/index', 'delete');
$this->set('checkProI5', $checkProI5);
$checkProV1 = $this->Acl->check($profile, 'Professionals/view');
$this->set('checkProV1', $checkProV1);
$checkProV2 = $this->Acl->check($profile, 'Professionals/view', 'create');
$this->set('checkProV2', $checkProV2);
$checkProV3 = $this->Acl->check($profile, 'Professionals/view', 'read');
$this->set('checkProV3', $checkProV3);
$checkProV4 = $this->Acl->check($profile, 'Professionals/view', 'update');
$this->set('checkProV4', $checkProV4);
$checkProV5 = $this->Acl->check($profile, 'Professionals/view', 'delete');
$this->set('checkProV5', $checkProV5);
$checkPrA1 = $this->Acl->check($profile, 'Professions/add');
$this->set('checkPrA1', $checkPrA1);
$checkPrA2 = $this->Acl->check($profile, 'Professions/add', 'create');
$this->set('checkPrA2', $checkPrA2);
$checkPrD1 = $this->Acl->check($profile, 'Professions/delete');
$this->set('checkPrD1', $checkPrD1);
$checkPrD2 = $this->Acl->check($profile, 'Professions/delete', 'delete');
$this->set('checkPrD2', $checkPrD2);
$checkPrE1 = $this->Acl->check($profile, 'Professions/edit');
$this->set('checkPrE1', $checkPrE1);
$checkPrE2 = $this->Acl->check($profile, 'Professions/edit', 'update');
$this->set('checkPrE2', $checkPrE2);
$checkPrI1 = $this->Acl->check($profile, 'Professions/index');
$this->set('checkPrI1', $checkPrI1);
$checkPrI2 = $this->Acl->check($profile, 'Professions/index', 'create');
$this->set('checkPrI2', $checkPrI2);
$checkPrI3 = $this->Acl->check($profile, 'Professions/index', 'read');
$this->set('checkPrI3', $checkPrI3);
$checkPrI4 = $this->Acl->check($profile, 'Professions/index', 'update');
$this->set('checkPrI4', $checkPrI4);
$checkPrI5 = $this->Acl->check($profile, 'Professions/index', 'delete');
$this->set('checkPrI5', $checkPrI5);
$checkPrV1 = $this->Acl->check($profile, 'Professions/view');
$this->set('checkPrV1', $checkPrV1);
$checkPrV2 = $this->Acl->check($profile, 'Professions/view', 'create');
$this->set('checkPrV2', $checkPrV2);
$checkPrV3 = $this->Acl->check($profile, 'Professions/view', 'read');
$this->set('checkPrV3', $checkPrV3);
$checkPrV4 = $this->Acl->check($profile, 'Professions/view', 'update');
$this->set('checkPrV4', $checkPrV4);
$checkPrV5 = $this->Acl->check($profile, 'Professions/view', 'delete');
$this->set('checkPrV5', $checkPrV5);
$checkPeA1 = $this->Acl->check($profile, 'Profiles/add');
$this->set('checkPeA1', $checkPeA1);
$checkPeA2 = $this->Acl->check($profile, 'Profiles/add', 'create');
$this->set('checkPeA2', $checkPeA2);
$checkPeD1 = $this->Acl->check($profile, 'Profiles/delete');
$this->set('checkPeD1', $checkPeD1);
$checkPeD2 = $this->Acl->check($profile, 'Profiles/delete', 'delete');
$this->set('checkPeD2', $checkPeD2);
$checkPeE1 = $this->Acl->check($profile, 'Profiles/edit');
$this->set('checkPeE1', $checkPeE1);
$checkPeE2 = $this->Acl->check($profile, 'Profiles/edit', 'update');
$this->set('checkPeE2', $checkPeE2);
$checkPeI1 = $this->Acl->check($profile, 'Profiles/index');
$this->set('checkPeI1', $checkPeI1);
$checkPeI2 = $this->Acl->check($profile, 'Profiles/index', 'create');
$this->set('checkPeI2', $checkPeI2);
$checkPeI3 = $this->Acl->check($profile, 'Profiles/index', 'read');
$this->set('checkPeI3', $checkPeI3);
$checkPeI4 = $this->Acl->check($profile, 'Profiles/index', 'update');
$this->set('checkPeI4', $checkPeI4);
$checkPeI5 = $this->Acl->check($profile, 'Profiles/index', 'delete');
$this->set('checkPeI5', $checkPeI5);
$checkPeV1 = $this->Acl->check($profile, 'Profiles/view');
$this->set('checkPeV1', $checkPeV1);
$checkPeV2 = $this->Acl->check($profile, 'Profiles/view', 'create');
$this->set('checkPeV2', $checkPeV2);
$checkPeV3 = $this->Acl->check($profile, 'Profiles/view', 'read');
$this->set('checkPeV3', $checkPeV3);
$checkPeV4 = $this->Acl->check($profile, 'Profiles/view', 'update');
$this->set('checkPeV4', $checkPeV4);
$checkPeV5 = $this->Acl->check($profile, 'Profiles/view', 'delete');
$this->set('checkPeV5', $checkPeV5);
$checkPA1 = $this->Acl->check($profile, 'Provinces/add');
$this->set('checkPA1', $checkPA1);
$checkPA2 = $this->Acl->check($profile, 'Provinces/add', 'create');
$this->set('checkPA2', $checkPA2);
$checkPD1 = $this->Acl->check($profile, 'Provinces/delete');
$this->set('checkPD1', $checkPD1);
$checkPD2 = $this->Acl->check($profile, 'Provinces/delete', 'delete');
$this->set('checkPD2', $checkPD2);
$checkPE1 = $this->Acl->check($profile, 'Provinces/edit');
$this->set('checkPE1', $checkPE1);
$checkPE2 = $this->Acl->check($profile, 'Provinces/edit', 'update');
$this->set('checkPE2', $checkPE2);
$checkPI1 = $this->Acl->check($profile, 'Provinces/index');
$this->set('checkPI1', $checkPI1);
$checkPI2 = $this->Acl->check($profile, 'Provinces/index', 'create');
$this->set('checkPI2', $checkPI2);
$checkPI3 = $this->Acl->check($profile, 'Provinces/index', 'read');
$this->set('checkPI3', $checkPI3);
$checkPI4 = $this->Acl->check($profile, 'Provinces/index', 'update');
$this->set('checkPI4', $checkPI4);
$checkPI5 = $this->Acl->check($profile, 'Provinces/index', 'delete');
$this->set('checkPI5', $checkPI5);
$checkPV1 = $this->Acl->check($profile, 'Provinces/view');
$this->set('checkPV1', $checkPV1);
$checkPV2 = $this->Acl->check($profile, 'Provinces/view', 'create');
$this->set('checkPV2', $checkPV2);
$checkPV3 = $this->Acl->check($profile, 'Provinces/view', 'read');
$this->set('checkPV3', $checkPV3);
$checkPV4 = $this->Acl->check($profile, 'Provinces/view', 'update');
$this->set('checkPV4', $checkPV4);
$checkPV5 = $this->Acl->check($profile, 'Provinces/view', 'delete');
$this->set('checkPV5', $checkPV5);
$checkTA1 = $this->Acl->check($profile, 'Teams/add');
$this->set('checkTA1', $checkTA1);
$checkTA2 = $this->Acl->check($profile, 'Teams/add', 'create');
$this->set('checkTA2', $checkTA2);
$checkTD1 = $this->Acl->check($profile, 'Teams/delete');
$this->set('checkTD1', $checkTD1);
$checkTD2 = $this->Acl->check($profile, 'Teams/delete', 'delete');
$this->set('checkTD2', $checkTD2);
$checkTE1 = $this->Acl->check($profile, 'Teams/edit');
$this->set('checkTE1', $checkTE1);
$checkTE2 = $this->Acl->check($profile, 'Teams/edit', 'update');
$this->set('checkTE2', $checkTE2);
$checkTI1 = $this->Acl->check($profile, 'Teams/index');
$this->set('checkTI1', $checkTI1);
$checkTI2 = $this->Acl->check($profile, 'Teams/index', 'create');
$this->set('checkTI2', $checkTI2);
$checkTI3 = $this->Acl->check($profile, 'Teams/index', 'read');
$this->set('checkTI3', $checkTI3);
$checkTI4 = $this->Acl->check($profile, 'Teams/index', 'update');
$this->set('checkTI4', $checkTI4);
$checkTI5 = $this->Acl->check($profile, 'Teams/index', 'delete');
$this->set('checkTI5', $checkTI5);
$checkTV1 = $this->Acl->check($profile, 'Teams/view');
$this->set('checkTV1', $checkTV1);
$checkTV2 = $this->Acl->check($profile, 'Teams/view', 'create');
$this->set('checkTV2', $checkTV2);
$checkTV3 = $this->Acl->check($profile, 'Teams/view', 'read');
$this->set('checkTV3', $checkTV3);
$checkTV4 = $this->Acl->check($profile, 'Teams/view', 'update');
$this->set('checkTV4', $checkTV4);
$checkTV5 = $this->Acl->check($profile, 'Teams/view', 'delete');
$this->set('checkTV5', $checkTV5);
$checkUA1 = $this->Acl->check($profile, 'Users/add');
$this->set('checkUA1', $checkUA1);
$checkUA2 = $this->Acl->check($profile, 'Users/add', 'create');
$this->set('checkUA2', $checkUA2);
$checkUD1 = $this->Acl->check($profile, 'Users/delete');
$this->set('checkUD1', $checkUD1);
$checkUD2 = $this->Acl->check($profile, 'Users/delete', 'delete');
$this->set('checkUD2', $checkUD2);
$checkUE1 = $this->Acl->check($profile, 'Users/edit');
$this->set('checkUE1', $checkUE1);
$checkUE2 = $this->Acl->check($profile, 'Users/edit', 'update');
$this->set('checkUE2', $checkUE2);
$checkUI1 = $this->Acl->check($profile, 'Users/index');
$this->set('checkUI1', $checkUI1);
$checkUI2 = $this->Acl->check($profile, 'Users/index', 'create');
$this->set('checkUI2', $checkUI2);
$checkUI3 = $this->Acl->check($profile, 'Users/index', 'read');
$this->set('checkUI3', $checkUI3);
$checkUI4 = $this->Acl->check($profile, 'Users/index', 'update');
$this->set('checkUI4', $checkUI4);
$checkUI5 = $this->Acl->check($profile, 'Users/index', 'delete');
$this->set('checkUI5', $checkUI5);
$checkUV1 = $this->Acl->check($profile, 'Users/view');
$this->set('checkUV1', $checkUV1);
$checkUV2 = $this->Acl->check($profile, 'Users/view', 'create');
$this->set('checkUV2', $checkUV2);
$checkUV3 = $this->Acl->check($profile, 'Users/view', 'read');
$this->set('checkUV3', $checkUV3);
$checkUV4 = $this->Acl->check($profile, 'Users/view', 'update');
$this->set('checkUV4', $checkUV4);
$checkUV5 = $this->Acl->check($profile, 'Users/view', 'delete');
$this->set('checkUV5', $checkUV5);
}
return $this->render('/home');
}
And this is the code of navbar.php:
<?php if(!empty($userApp)){ ?>
<?= $this->Html->tag('div', $this->Html->image($userApp->professional->image_url,
['style'=>'float: left;border-radius:50%;width:90px;height:90px;margin:10px;'])
.$this->Html->tag('p', h($userApp->professional->full_name))
.$this->Html->tag('p', 'Profesión: '.h($userApp->professional->profession->name))
.$this->Html->tag('p', 'Rol: '.h($userApp->profile->name))
.$this->Html->link('Cambiar contraseña', ['controller' => 'Users', 'action' => 'changepassword', $id]), ['style' => 'margin:10px']) ?>
<?php } ?>
<?php $icon = !empty($userApp) ? $this->Html->tag("span", "", ['class'=>'glyphicon glyphicon-user']) :
$this->Html->link($this->Html->tag("span", "", ['class'=>'glyphicon glyphicon-user']),['controller'=>'Users','action'=>'changepassword', $id],
['escape' => false, 'title' => 'Cambiar contraseña']); ?>
<?= !empty($username) ? $this->Html->tag('span', $this->Html->link(__('Calificador CIF'),['controller'=>'Home','action'=>'index'], ['title' => 'Inicio']),
['style' => 'margin-left:10px;'])." | ".$icon." ".$username : $this->Html->link(__('Calificador CIF'),['controller'=>'Users','action'=>'login']) ?>
<?php if(!empty($username)){ ?>
<?php
$control = !empty($profiles) && $count > 1 ? $this->Html->tag('span', $this->Form->control('profile_id', ['label' => false, 'options' => $profiles,
'empty' => '- Seleccione un perfil -', 'id' => 'profile_id']), ['class' => 'float-right']) : '';
echo $this->Form->create();
echo $this->Html->tag('div', $this->Html->link('Salir', ['controller' => 'Users', 'action' => 'logout'], ['class' => 'button'])
.$control, ['class' => 'title_bar']);
echo $this->Form->end();
?>
<?php
}
if(!empty($id)){
?>
<div style="margin-left:10px;float:left">
<nav class="navbar navbar-expand-lg">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar flex-column bg-body-secondary">
<li class="nav-item dropdown dropdown-hover">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Administración
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
<li><?= !empty($checkCI1) || !empty($checkCI2) || !empty($checkCI3) || !empty($checkCI4) || !empty($checkCI5) ? $this->Html->link('Administración de Países', ['controller'=>'Countries','action'=>'index'], ['class'=>'dropdown-item']) : '' ?></li>
<li><?= !empty($checkPI1) || !empty($checkPI2) || !empty($checkPI3) || !empty($checkPI4) || !empty($checkPI5) ? $this->Html->link('Administración de Provincias', ['controller'=>'Provinces','action'=>'index'], ['class'=>'dropdown-item']) : '' ?></li>
<li><?= !empty($checkLI1) || !empty($checkLI2) || !empty($checkLI3) || !empty($checkLI4) || !empty($checkLI5) ? $this->Html->link('Administración de Localidades', ['controller'=>'Localities','action'=>'index'], ['class'=>'dropdown-item']) : '' ?></li>
<li><?= !empty($checkPaI1) || !empty($checkPaI2) || !empty($checkPaI3) || !empty($checkPaI4) || !empty($checkPaI5) ? $this->Html->link('Administración de Pacientes', ['controller'=>'Pacients','action'=>'index'], ['class'=>'dropdown-item']) : '' ?></li>
<li><?= !empty($checkPrI1) || !empty($checkPrI2) || !empty($checkPrI3) || !empty($checkPrI4) || !empty($checkPrI5) ? $this->Html->link('Administración de Profesiones', ['controller'=>'Professions','action'=>'index'], ['class'=>'dropdown-item']) : '' ?></li>
<li><?= !empty($checkProI1) || !empty($checkProI2) || !empty($checkProI3) || !empty($checkProI4) || !empty($checkProI5) ? $this->Html->link('Administración de Profesionales', ['controller'=>'Professionals','action'=>'index'], ['class'=>'dropdown-item']) : '' ?></li>
<li><?= !empty($checkTI1) || !empty($checkTI2) || !empty($checkTI3) || !empty($checkTI4) || !empty($checkTI5) ? $this->Html->link('Administración de Equipos', ['controller'=>'Teams','action'=>'index'], ['class'=>'dropdown-item']) : '' ?></li>
<li><?= !empty($checkPeI1) || !empty($checkPeI2) || !empty($checkPeI3) || !empty($checkPeI4) || !empty($checkPeI5) ? $this->Html->link('Administración de Perfiles', ['controller'=>'Profiles','action'=>'index'], ['class'=>'dropdown-item']) : '' ?></li>
<li><?= !empty($checkMI1) || !empty($checkMI2) || !empty($checkMI3) || !empty($checkMI4) || !empty($checkMI5) ? $this->Html->link('Administración de Permisos', ['controller'=>'MyPermissions','action'=>'index'], ['class'=>'dropdown-item']) : '' ?></li>
<li><?= !empty($checkUI1) || !empty($checkUI2) || !empty($checkUI3) || !empty($checkUI4) || !empty($checkUI5) ? $this->Html->link('Administración de Usuarios', ['controller'=>'Users','action'=>'index'], ['class'=>'dropdown-item']) : '' ?></li>
</ul>
</li>
</ul>
</div><!-- /.collapse -->
</nav><!-- /.container-fluid -->
</div>
<script>
$(function(){
$('#profile_id').change(function(){
$.ajax({
method:"GET",
url:"<?= $this->Url->build(['controller' => 'Users', 'action' => 'changeProfile']) ?>",
data:{
profile_id:$(this).val()
},
success: function() {
alert('entra');
},
headers:{
'X-CSRF-Token':$('meta[name="csrfToken"]').attr('content')
}
});
});
})
</script>
<?php } ?>
in your success instead of alert you need update the html. Maybe you understand wrong the difference between javascript client side and php server side?
anyway since you have so many things to update like your links and such. Actually submit the form instead of ajax call may make more sense in your case…
Thank you @thomasg, that worked, but now is giving me an error 403 (forbidden) in the page.
This is the code for action changeProfile:
public function changeProfile()
{
$session = $this->request->getSession();
$this->loadModel('MyPermissions');
$this->loadModel('Teams');
if($this->request->is('post')){
$user_id = $this->Auth->user('id');
$session->write(['profile_id' => $this->request->getData('profile_id')]);
$profile_id = $session->consume('profile_id');
$this->profile_id = $profile_id;
if(!empty($this->professional_id)){
$userApp = $this->Users->get($user_id, ['contain' => ['Professionals.Professions', 'Profiles' => function (Query $q) use ($profile_id){
return $q->where(['Profiles.id' => $profile_id]);
}]]);
$profiles = $this->Users->Profiles->find('list')->join([
'ProfessionalsTeams' => ['table' => 'professionals_teams',
'type' => 'LEFT',
'conditions' => 'ProfessionalsTeams.profile_id = Profiles.id'],
'Users' => ['table' => 'users',
'type' => 'LEFT',
'conditions' => 'Users.profile_id = Profiles.id']])->where(['or' => ['Users.professional_id' => $this->professional_id,
'ProfessionalsTeams.professional_id' => $this->professional_id]])->all();
$this->set(compact('userApp', 'profiles'));
$this->set('count', count($profiles));
}
if(!empty($profile_id)){
if($profile_id==3){
$this->viewBuilder()->setLayout('professional');
$this->paginate = ['contain' => 'Pacients'];
$teams = $this->paginate($this->Teams->find('all')->matching('ProfessionalsTeams')
->where(['ProfessionalsTeams.professional_id' => $this->professional_id]));
$this->set(compact('teams'));
$date = new FrozenDate(date('Y-m-d'));
$this->set('date', $date);
}
$profile = $this->Profiles->get($profile_id);
$checkCA1 = $this->Acl->check($profile, 'Countries/add');
$this->set('checkCA1', $checkCA1);
$checkCA2 = $this->Acl->check($profile, 'Countries/add', 'create');
$this->set('checkCA2', $checkCA2);
$checkCD1 = $this->Acl->check($profile, 'Countries/delete');
$this->set('checkCD1', $checkCD1);
$checkCD2 = $this->Acl->check($profile, 'Countries/delete', 'delete');
$this->set('checkCD2', $checkCD2);
$checkCE1 = $this->Acl->check($profile, 'Countries/edit');
$this->set('checkCE1', $checkCE1);
$checkCE2 = $this->Acl->check($profile, 'Countries/edit', 'update');
$this->set('checkCE2', $checkCE2);
$checkCI1 = $this->Acl->check($profile, 'Countries/index');
$this->set('checkCI1', $checkCI1);
$checkCI2 = $this->Acl->check($profile, 'Countries/index', 'create');
$this->set('checkCI2', $checkCI2);
$checkCI3 = $this->Acl->check($profile, 'Countries/index', 'read');
$this->set('checkCI3', $checkCI3);
$checkCI4 = $this->Acl->check($profile, 'Countries/index', 'update');
$this->set('checkCI4', $checkCI4);
$checkCI5 = $this->Acl->check($profile, 'Countries/index', 'delete');
$this->set('checkCI5', $checkCI5);
$checkCV1 = $this->Acl->check($profile, 'Countries/view');
$this->set('checkCV1', $checkCV1);
$checkCV2 = $this->Acl->check($profile, 'Countries/view', 'create');
$this->set('checkCV2', $checkCV2);
$checkCV3 = $this->Acl->check($profile, 'Countries/view', 'read');
$this->set('checkCV3', $checkCV3);
$checkCV4 = $this->Acl->check($profile, 'Countries/view', 'update');
$this->set('checkCV4', $checkCV4);
$checkCV5 = $this->Acl->check($profile, 'Countries/view', 'delete');
$this->set('checkCV5', $checkCV5);
$checkHI1 = $this->Acl->check($profile, 'Home/index');
$this->set('checkHI1', $checkHI1);
$checkHI2 = $this->Acl->check($profile, 'Home/index', 'create');
$this->set('checkHI2', $checkHI2);
$checkHI3 = $this->Acl->check($profile, 'Home/index', 'read');
$this->set('checkHI3', $checkHI3);
$checkHI4 = $this->Acl->check($profile, 'Home/index', 'update');
$this->set('checkHI4', $checkHI4);
$checkHI5 = $this->Acl->check($profile, 'Home/index', 'delete');
$this->set('checkHI5', $checkHI5);
$checkLA1 = $this->Acl->check($profile, 'Localities/add');
$this->set('checkLA1', $checkLA1);
$checkLA2 = $this->Acl->check($profile, 'Localities/add', 'create');
$this->set('checkLA2', $checkLA2);
$checkLD1 = $this->Acl->check($profile, 'Localities/delete');
$this->set('checkLD1', $checkLD1);
$checkLD2 = $this->Acl->check($profile, 'Localities/delete', 'delete');
$this->set('checkLD2', $checkLD2);
$checkLE1 = $this->Acl->check($profile, 'Localities/edit');
$this->set('checkLE1', $checkLE1);
$checkLE2 = $this->Acl->check($profile, 'Localities/edit', 'update');
$this->set('checkLE2', $checkLE2);
$checkLI1 = $this->Acl->check($profile, 'Localities/index');
$this->set('checkLI1', $checkLI1);
$checkLI2 = $this->Acl->check($profile, 'Localities/index', 'create');
$this->set('checkLI2', $checkLI2);
$checkLI3 = $this->Acl->check($profile, 'Localities/index', 'read');
$this->set('checkLI3', $checkLI3);
$checkLI4 = $this->Acl->check($profile, 'Localities/index', 'update');
$this->set('checkLI4', $checkLI4);
$checkLI5 = $this->Acl->check($profile, 'Localities/index', 'delete');
$this->set('checkLI5', $checkLI5);
$checkLV1 = $this->Acl->check($profile, 'Localities/view');
$this->set('checkLV1', $checkLV1);
$checkLV2 = $this->Acl->check($profile, 'Localities/view', 'create');
$this->set('checkLV2', $checkLV2);
$checkLV3 = $this->Acl->check($profile, 'Localities/view', 'read');
$this->set('checkLV3', $checkLV3);
$checkLV4 = $this->Acl->check($profile, 'Localities/view', 'update');
$this->set('checkLV4', $checkLV4);
$checkLV5 = $this->Acl->check($profile, 'Localities/view', 'delete');
$this->set('checkLV5', $checkLV5);
$checkMA1 = $this->Acl->check($profile, 'MyPermissions/add');
$this->set('checkMA1', $checkMA1);
$checkMA2 = $this->Acl->check($profile, 'MyPermissions/add', 'create');
$this->set('checkMA2', $checkMA2);
$checkMD1 = $this->Acl->check($profile, 'MyPermissions/delete');
$this->set('checkMD1', $checkMD1);
$checkMD2 = $this->Acl->check($profile, 'MyPermissions/delete', 'delete');
$this->set('checkMD2', $checkMD2);
$checkME1 = $this->Acl->check($profile, 'MyPermissions/edit');
$this->set('checkME1', $checkME1);
$checkME2 = $this->Acl->check($profile, 'MyPermissions/edit', 'update');
$this->set('checkME2', $checkME2);
$checkMI1 = $this->Acl->check($profile, 'MyPermissions/index');
$this->set('checkMI1', $checkMI1);
$checkMI2 = $this->Acl->check($profile, 'MyPermissions/index', 'create');
$this->set('checkMI2', $checkMI2);
$checkMI3 = $this->Acl->check($profile, 'MyPermissions/index', 'read');
$this->set('checkMI3', $checkMI3);
$checkMI4 = $this->Acl->check($profile, 'MyPermissions/index', 'update');
$this->set('checkMI4', $checkMI4);
$checkMI5 = $this->Acl->check($profile, 'MyPermissions/index', 'delete');
$this->set('checkMI5', $checkMI5);
$checkMV1 = $this->Acl->check($profile, 'MyPermissions/view');
$this->set('checkMV1', $checkMV1);
$checkMV2 = $this->Acl->check($profile, 'MyPermissions/view', 'create');
$this->set('checkMV2', $checkMV2);
$checkMV3 = $this->Acl->check($profile, 'MyPermissions/view', 'read');
$this->set('checkMV3', $checkMV3);
$checkMV4 = $this->Acl->check($profile, 'MyPermissions/view', 'update');
$this->set('checkMV4', $checkMV4);
$checkMV5 = $this->Acl->check($profile, 'MyPermissions/view', 'delete');
$this->set('checkMV5', $checkMV5);
$checkPaA1 = $this->Acl->check($profile, 'Pacients/add');
$this->set('checkPaA1', $checkPaA1);
$checkPaA2 = $this->Acl->check($profile, 'Pacients/add', 'create');
$this->set('checkPaA2', $checkPaA2);
$checkPaD1 = $this->Acl->check($profile, 'Pacients/delete');
$this->set('checkPaD1', $checkPaD1);
$checkPaD2 = $this->Acl->check($profile, 'Pacients/delete', 'delete');
$this->set('checkPaD2', $checkPaD2);
$checkPaE1 = $this->Acl->check($profile, 'Pacients/edit');
$this->set('checkPaE1', $checkPaE1);
$checkPaE2 = $this->Acl->check($profile, 'Pacients/edit', 'update');
$this->set('checkPaE2', $checkPaE2);
$checkPaI1 = $this->Acl->check($profile, 'Pacients/index');
$this->set('checkPaI1', $checkPaI1);
$checkPaI2 = $this->Acl->check($profile, 'Pacients/index', 'create');
$this->set('checkPaI2', $checkPaI2);
$checkPaI3 = $this->Acl->check($profile, 'Pacients/index', 'read');
$this->set('checkPaI3', $checkPaI3);
$checkPaI4 = $this->Acl->check($profile, 'Pacients/index', 'update');
$this->set('checkPaI4', $checkPaI4);
$checkPaI5 = $this->Acl->check($profile, 'Pacients/index', 'delete');
$this->set('checkPaI5', $checkPaI5);
$checkPaV1 = $this->Acl->check($profile, 'Pacients/view');
$this->set('checkPaV1', $checkPaV1);
$checkPaV2 = $this->Acl->check($profile, 'Pacients/view', 'create');
$this->set('checkPaV2', $checkPaV2);
$checkPaV3 = $this->Acl->check($profile, 'Pacients/view', 'read');
$this->set('checkPaV3', $checkPaV3);
$checkPaV4 = $this->Acl->check($profile, 'Pacients/view', 'update');
$this->set('checkPaV4', $checkPaV4);
$checkPaV5 = $this->Acl->check($profile, 'Pacients/view', 'delete');
$this->set('checkPaV5', $checkPaV5);
$checkProA1 = $this->Acl->check($profile, 'Professionals/add');
$this->set('checkProA1', $checkProA1);
$checkProA2 = $this->Acl->check($profile, 'Professionals/add', 'create');
$this->set('checkProA2', $checkProA2);
$checkProD1 = $this->Acl->check($profile, 'Professionals/delete');
$this->set('checkProD1', $checkProD1);
$checkProD2 = $this->Acl->check($profile, 'Professionals/delete', 'delete');
$this->set('checkProD2', $checkProD2);
$checkProE1 = $this->Acl->check($profile, 'Professionals/edit');
$this->set('checkProE1', $checkProE1);
$checkProE2 = $this->Acl->check($profile, 'Professionals/edit', 'update');
$this->set('checkProE2', $checkProE2);
$checkProI1 = $this->Acl->check($profile, 'Professionals/index');
$this->set('checkProI1', $checkProI1);
$checkProI2 = $this->Acl->check($profile, 'Professionals/index', 'create');
$this->set('checkProI2', $checkProI2);
$checkProI3 = $this->Acl->check($profile, 'Professionals/index', 'read');
$this->set('checkProI3', $checkProI3);
$checkProI4 = $this->Acl->check($profile, 'Professionals/index', 'update');
$this->set('checkProI4', $checkProI4);
$checkProI5 = $this->Acl->check($profile, 'Professionals/index', 'delete');
$this->set('checkProI5', $checkProI5);
$checkProV1 = $this->Acl->check($profile, 'Professionals/view');
$this->set('checkProV1', $checkProV1);
$checkProV2 = $this->Acl->check($profile, 'Professionals/view', 'create');
$this->set('checkProV2', $checkProV2);
$checkProV3 = $this->Acl->check($profile, 'Professionals/view', 'read');
$this->set('checkProV3', $checkProV3);
$checkProV4 = $this->Acl->check($profile, 'Professionals/view', 'update');
$this->set('checkProV4', $checkProV4);
$checkProV5 = $this->Acl->check($profile, 'Professionals/view', 'delete');
$this->set('checkProV5', $checkProV5);
$checkPrA1 = $this->Acl->check($profile, 'Professions/add');
$this->set('checkPrA1', $checkPrA1);
$checkPrA2 = $this->Acl->check($profile, 'Professions/add', 'create');
$this->set('checkPrA2', $checkPrA2);
$checkPrD1 = $this->Acl->check($profile, 'Professions/delete');
$this->set('checkPrD1', $checkPrD1);
$checkPrD2 = $this->Acl->check($profile, 'Professions/delete', 'delete');
$this->set('checkPrD2', $checkPrD2);
$checkPrE1 = $this->Acl->check($profile, 'Professions/edit');
$this->set('checkPrE1', $checkPrE1);
$checkPrE2 = $this->Acl->check($profile, 'Professions/edit', 'update');
$this->set('checkPrE2', $checkPrE2);
$checkPrI1 = $this->Acl->check($profile, 'Professions/index');
$this->set('checkPrI1', $checkPrI1);
$checkPrI2 = $this->Acl->check($profile, 'Professions/index', 'create');
$this->set('checkPrI2', $checkPrI2);
$checkPrI3 = $this->Acl->check($profile, 'Professions/index', 'read');
$this->set('checkPrI3', $checkPrI3);
$checkPrI4 = $this->Acl->check($profile, 'Professions/index', 'update');
$this->set('checkPrI4', $checkPrI4);
$checkPrI5 = $this->Acl->check($profile, 'Professions/index', 'delete');
$this->set('checkPrI5', $checkPrI5);
$checkPrV1 = $this->Acl->check($profile, 'Professions/view');
$this->set('checkPrV1', $checkPrV1);
$checkPrV2 = $this->Acl->check($profile, 'Professions/view', 'create');
$this->set('checkPrV2', $checkPrV2);
$checkPrV3 = $this->Acl->check($profile, 'Professions/view', 'read');
$this->set('checkPrV3', $checkPrV3);
$checkPrV4 = $this->Acl->check($profile, 'Professions/view', 'update');
$this->set('checkPrV4', $checkPrV4);
$checkPrV5 = $this->Acl->check($profile, 'Professions/view', 'delete');
$this->set('checkPrV5', $checkPrV5);
$checkPeA1 = $this->Acl->check($profile, 'Profiles/add');
$this->set('checkPeA1', $checkPeA1);
$checkPeA2 = $this->Acl->check($profile, 'Profiles/add', 'create');
$this->set('checkPeA2', $checkPeA2);
$checkPeD1 = $this->Acl->check($profile, 'Profiles/delete');
$this->set('checkPeD1', $checkPeD1);
$checkPeD2 = $this->Acl->check($profile, 'Profiles/delete', 'delete');
$this->set('checkPeD2', $checkPeD2);
$checkPeE1 = $this->Acl->check($profile, 'Profiles/edit');
$this->set('checkPeE1', $checkPeE1);
$checkPeE2 = $this->Acl->check($profile, 'Profiles/edit', 'update');
$this->set('checkPeE2', $checkPeE2);
$checkPeI1 = $this->Acl->check($profile, 'Profiles/index');
$this->set('checkPeI1', $checkPeI1);
$checkPeI2 = $this->Acl->check($profile, 'Profiles/index', 'create');
$this->set('checkPeI2', $checkPeI2);
$checkPeI3 = $this->Acl->check($profile, 'Profiles/index', 'read');
$this->set('checkPeI3', $checkPeI3);
$checkPeI4 = $this->Acl->check($profile, 'Profiles/index', 'update');
$this->set('checkPeI4', $checkPeI4);
$checkPeI5 = $this->Acl->check($profile, 'Profiles/index', 'delete');
$this->set('checkPeI5', $checkPeI5);
$checkPeV1 = $this->Acl->check($profile, 'Profiles/view');
$this->set('checkPeV1', $checkPeV1);
$checkPeV2 = $this->Acl->check($profile, 'Profiles/view', 'create');
$this->set('checkPeV2', $checkPeV2);
$checkPeV3 = $this->Acl->check($profile, 'Profiles/view', 'read');
$this->set('checkPeV3', $checkPeV3);
$checkPeV4 = $this->Acl->check($profile, 'Profiles/view', 'update');
$this->set('checkPeV4', $checkPeV4);
$checkPeV5 = $this->Acl->check($profile, 'Profiles/view', 'delete');
$this->set('checkPeV5', $checkPeV5);
$checkPA1 = $this->Acl->check($profile, 'Provinces/add');
$this->set('checkPA1', $checkPA1);
$checkPA2 = $this->Acl->check($profile, 'Provinces/add', 'create');
$this->set('checkPA2', $checkPA2);
$checkPD1 = $this->Acl->check($profile, 'Provinces/delete');
$this->set('checkPD1', $checkPD1);
$checkPD2 = $this->Acl->check($profile, 'Provinces/delete', 'delete');
$this->set('checkPD2', $checkPD2);
$checkPE1 = $this->Acl->check($profile, 'Provinces/edit');
$this->set('checkPE1', $checkPE1);
$checkPE2 = $this->Acl->check($profile, 'Provinces/edit', 'update');
$this->set('checkPE2', $checkPE2);
$checkPI1 = $this->Acl->check($profile, 'Provinces/index');
$this->set('checkPI1', $checkPI1);
$checkPI2 = $this->Acl->check($profile, 'Provinces/index', 'create');
$this->set('checkPI2', $checkPI2);
$checkPI3 = $this->Acl->check($profile, 'Provinces/index', 'read');
$this->set('checkPI3', $checkPI3);
$checkPI4 = $this->Acl->check($profile, 'Provinces/index', 'update');
$this->set('checkPI4', $checkPI4);
$checkPI5 = $this->Acl->check($profile, 'Provinces/index', 'delete');
$this->set('checkPI5', $checkPI5);
$checkPV1 = $this->Acl->check($profile, 'Provinces/view');
$this->set('checkPV1', $checkPV1);
$checkPV2 = $this->Acl->check($profile, 'Provinces/view', 'create');
$this->set('checkPV2', $checkPV2);
$checkPV3 = $this->Acl->check($profile, 'Provinces/view', 'read');
$this->set('checkPV3', $checkPV3);
$checkPV4 = $this->Acl->check($profile, 'Provinces/view', 'update');
$this->set('checkPV4', $checkPV4);
$checkPV5 = $this->Acl->check($profile, 'Provinces/view', 'delete');
$this->set('checkPV5', $checkPV5);
$checkTA1 = $this->Acl->check($profile, 'Teams/add');
$this->set('checkTA1', $checkTA1);
$checkTA2 = $this->Acl->check($profile, 'Teams/add', 'create');
$this->set('checkTA2', $checkTA2);
$checkTD1 = $this->Acl->check($profile, 'Teams/delete');
$this->set('checkTD1', $checkTD1);
$checkTD2 = $this->Acl->check($profile, 'Teams/delete', 'delete');
$this->set('checkTD2', $checkTD2);
$checkTE1 = $this->Acl->check($profile, 'Teams/edit');
$this->set('checkTE1', $checkTE1);
$checkTE2 = $this->Acl->check($profile, 'Teams/edit', 'update');
$this->set('checkTE2', $checkTE2);
$checkTI1 = $this->Acl->check($profile, 'Teams/index');
$this->set('checkTI1', $checkTI1);
$checkTI2 = $this->Acl->check($profile, 'Teams/index', 'create');
$this->set('checkTI2', $checkTI2);
$checkTI3 = $this->Acl->check($profile, 'Teams/index', 'read');
$this->set('checkTI3', $checkTI3);
$checkTI4 = $this->Acl->check($profile, 'Teams/index', 'update');
$this->set('checkTI4', $checkTI4);
$checkTI5 = $this->Acl->check($profile, 'Teams/index', 'delete');
$this->set('checkTI5', $checkTI5);
$checkTV1 = $this->Acl->check($profile, 'Teams/view');
$this->set('checkTV1', $checkTV1);
$checkTV2 = $this->Acl->check($profile, 'Teams/view', 'create');
$this->set('checkTV2', $checkTV2);
$checkTV3 = $this->Acl->check($profile, 'Teams/view', 'read');
$this->set('checkTV3', $checkTV3);
$checkTV4 = $this->Acl->check($profile, 'Teams/view', 'update');
$this->set('checkTV4', $checkTV4);
$checkTV5 = $this->Acl->check($profile, 'Teams/view', 'delete');
$this->set('checkTV5', $checkTV5);
$checkUA1 = $this->Acl->check($profile, 'Users/add');
$this->set('checkUA1', $checkUA1);
$checkUA2 = $this->Acl->check($profile, 'Users/add', 'create');
$this->set('checkUA2', $checkUA2);
$checkUD1 = $this->Acl->check($profile, 'Users/delete');
$this->set('checkUD1', $checkUD1);
$checkUD2 = $this->Acl->check($profile, 'Users/delete', 'delete');
$this->set('checkUD2', $checkUD2);
$checkUE1 = $this->Acl->check($profile, 'Users/edit');
$this->set('checkUE1', $checkUE1);
$checkUE2 = $this->Acl->check($profile, 'Users/edit', 'update');
$this->set('checkUE2', $checkUE2);
$checkUI1 = $this->Acl->check($profile, 'Users/index');
$this->set('checkUI1', $checkUI1);
$checkUI2 = $this->Acl->check($profile, 'Users/index', 'create');
$this->set('checkUI2', $checkUI2);
$checkUI3 = $this->Acl->check($profile, 'Users/index', 'read');
$this->set('checkUI3', $checkUI3);
$checkUI4 = $this->Acl->check($profile, 'Users/index', 'update');
$this->set('checkUI4', $checkUI4);
$checkUI5 = $this->Acl->check($profile, 'Users/index', 'delete');
$this->set('checkUI5', $checkUI5);
$checkUV1 = $this->Acl->check($profile, 'Users/view');
$this->set('checkUV1', $checkUV1);
$checkUV2 = $this->Acl->check($profile, 'Users/view', 'create');
$this->set('checkUV2', $checkUV2);
$checkUV3 = $this->Acl->check($profile, 'Users/view', 'read');
$this->set('checkUV3', $checkUV3);
$checkUV4 = $this->Acl->check($profile, 'Users/view', 'update');
$this->set('checkUV4', $checkUV4);
$checkUV5 = $this->Acl->check($profile, 'Users/view', 'delete');
$this->set('checkUV5', $checkUV5);
}
}
return $this->redirect(['controller' => 'Home', 'action' => 'index']);
}
I saw the error.log file and the error is that the csrf token is invalid or is missing, how can I solve this issue?
The question of CSRF tokens in Ajax requests has been asked and answered here and on StackOverflow dozens of times.
Yes, thank you, I solved it, but now is giving me the exception Record not found in table “users”, this is the code where it gives me the exception:
$userApp = $this->Users->get($user_id, ['contain' => ['Professionals.Professions', 'Profiles' => function (Query $q) use ($profile_id){
return $q->where(['Profiles.id' => $profile_id]);
}]]);
And $user_id = $this->Auth->user(‘id’);
What am I doing wrong?
You’re using the old Auth component?
Yes, I am using that, because the Authentication plugin gives me an exception with the folder in local environment
That seems like a problem to solve, instead of using some deprecated code that you’re going to have to work to replace in the near future.
To be clear, you’re using the old Auth component everywhere in your app, and the new plugin is not in use anywhere? Or you’re using the old Auth plugin in this particular bit of code but the new plugin in other parts?
Auth component everywhere and Authentication anywhere.
Well, I guess you’d want to make sure that the session cookie is being sent through your Ajax request, and do some debugging to figure out if the session, etc. is being correctly initialized in this particular use case.
I’m also curious about these lines in your code:
$session->write(['profile_id' => $this->request->getData('profile_id')]);
$profile_id = $session->consume('profile_id');
$this->profile_id = $profile_id;
What’s the intent here? You’re putting something into the session, then immediately removing it, and saving it into a member variable that doesn’t seem to ever be used? What does this structure gain for you over simply
$profile_id = $this->request->getData('profile_id');
Because in AppController.php method beforeFilter I am assigning $this->Auth->user(‘profile_id’) to $profile_id, I need the $profile_id to check the permissions in Acl, when is the beforeFilter method executed?