I’m working with CodeIgniter 4 trying to use multigrid for two cruds but keep getting security errors like the ones below. When I make an exception to csrf in filters for this file and csrf for POST the errors stop and it works beautifully. My assumption is that I have some issue with csrf because disabling it seems to solves my problems. Is there anyway I can keep my csrf protections?
My error
Error: Forbidden.
Server Response:
{
“title”: “CodeIgniter\Security\Exceptions\SecurityException”,
“type”: “CodeIgniter\Security\Exceptions\SecurityException”,
“code”: 403,
“message”: “The action you requested is not allowed.”,
My code
public function multigrid() {
$crud = $this->_getGroceryCrudEnterprise();
$crud->setCsrfTokenName(csrf_token());
$crud->setCsrfTokenValue(csrf_hash());
$crud->setApiUrlPath('/forms.php/Guest/testgrid1');
$output = $crud->render();
$crud2 = $this->_getGroceryCrudEnterprise();
$crud2->setCsrfTokenName(csrf_token());
$crud2->setCsrfTokenValue(csrf_hash());
$crud2->setApiUrlPath('/forms.php/Guest/testgrid2');
$output2 = $crud2->render();
$output->output .= '<br/>' . $output2->output;
return $this->_example_output($output);
}
public function testgrid1(){
$crud = $this->_getGroceryCrudEnterprise('registration');
$crud->setCsrfTokenName(csrf_token());
$crud->setCsrfTokenValue(csrf_hash());
$crud->setTable('guests');
$output = $crud->render();
return $this->_example_output($output);
}
public function testgrid2(){
$crud = $this->_getGroceryCrudEnterprise('registration');
$crud->setCsrfTokenName(csrf_token());
$crud->setCsrfTokenValue(csrf_hash());
$crud->setTable('chinacompany');
$output = $crud->render();
return $this->_example_output($output);
}