⚠ 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

display edit page to specific user



zgames
  • profile picture
  • Member

Posted 22 May 2012 - 00:20 AM

right now i setup my table with users, i'm using tank_auth with roles so I can say



if ($this->tank_auth->is_role('admin')){
$crud = new grocery_CRUD();
$crud->set_table('users');
//other variables
} else {
//code that i need
}


my admin can crud, it works perfectly, however right now i'm trying to let for 'users' to only edit their inserted information on the edit page, but I can't figure out how to do it, they either can't access edit page because of the if statement or they can access all users tables and edit them, any suggestions?

kenvogt
  • profile picture
  • Member

Posted 22 May 2012 - 01:18 AM

You could do something like this:

$user_id = {pass the user id somehow};
if ($this->tank_auth->is_role('admin')){
$crud = new grocery_CRUD();
$crud->set_table('users');
//other variables
} else {
$crud = new grocery_CRUD();
$crud->set_table('users')
->where('id', $user_id);
//code that I need
}

zgames
  • profile picture
  • Member

Posted 22 May 2012 - 15:13 PM


function employees()
{
if ($this->tank_auth->is_role('admin')){
$crud = new grocery_CRUD();
$crud->set_table('users');
$output = $crud->render();
$this->_example_output($output);
} elseif($this->uri->segment(3) != $this->tank_auth->get_user_id()) {
redirect('/index/edit/'.$this->tank_auth->get_user_id());
}
else{
$crud = new grocery_CRUD();
$crud->set_table('users');
$output = $crud->render();
$this->_example_output($output);}
}


it seems to work the way i wanted it to work, just wanted to share the solution :)