unset_list error is unfriendly
- Single Page
Posted 17 May 2012 - 13:28 PM
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
Posted 17 May 2012 - 13:59 PM
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.
Posted 17 May 2012 - 15:00 PM