⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

unset_list error is unfriendly



amityweb
  • profile picture
  • Member

Posted 17 May 2012 - 13:28 PM

I have upgraded and am using unset_list

If I go to the list page I get the following error, instead of a friendly error:


Fatal error: Uncaught exception 'Exception' with message 'You don't have permissions for this operation' in /home/dbsystem/public_html/application/libraries/grocery_crud.php:3342 Stack trace: #0 /home/dbsystem/public_html/application/controllers/site.php(1037): grocery_CRUD->render() #1 /home/dbsystem/public_html/system/core/CodeIgniter.php(359): Site->users() #2 /home/dbsystem/public_html/index.php(205): require_once('/home/dbsystem/...') #3 {main} thrown in /home/dbsystem/public_html/application/libraries/grocery_crud.php on line 3342

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 17 May 2012 - 13:59 PM

This is on purpose so you can handle the exception. I didn't want to add a show_error there because then you cannot handle the exception. So a quick way to have a default Codeigniter error message is:


try{
$crud->render();
}
catch(Exception $e)
{
show_error($e->getMessage());
}


or if you want to do it with the right way and have a message for the user you can do it like this:


try{
$crud->render();
}catch(Exception $e)
{

if($e->getCode() == 14) //The 14 is the code of the "You don't have permissions" error on grocery CRUD.
{
$this->load->view('permission_denied.php');//This is a custom view that you have to create
//Or you can simply have an error message for this
//For example: show_error('You don\'t have permissions for this operation');
}
else
{
show_error($e->getMessage());
}
}


And if you want the user to have for example the add form you can easily copy the url of the add form for example: localhost/your_project/index.php/examples/test/add and simply direct him there. Or you can also do this:


try{
$crud->render();
}catch(Exception $e)
{

if($e->getCode() == 14) //The 14 is the code of the "You don't have permissions" error on grocery CRUD.
{
redirect(strtolower(__CLASS__).'/'.strtolower(__FUNCTION__).'/add');
}
else
{
show_error($e->getMessage());
}
}


You have the freedom to do whatever you like rather than have it into the core library.

amityweb
  • profile picture
  • Member

Posted 17 May 2012 - 15:00 PM

Ok great, thanks for letting me know.