⚠ 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

Only edit own entry



Woz_Mann
  • profile picture
  • Member

Posted 25 October 2013 - 01:54 AM

Hi All,

 

Does anyone know of a way in which I can restrict someone to editing their own entries?

 

Background: I am building 2 different CRUD solutions, and in both cases (unless they are an admin) I need to be able to restrict the user to being able to edit only their own entries.

 

Thanks

Woz


Robert
  • profile picture
  • Member

Posted 25 October 2013 - 10:08 AM

You can use a login library (ion_auth) and create a new column in the respective table "user_records" then in the GC function use :

 
// load user Id
$user = $this->ion_auth->user()->row();

 

// when adding new records - adds the user id to the new record - field user_records
$crud->change_field_type('user_records', 'hidden', $user->id);

 

// users can see only there records
$crud->where('user_records', $user->id);
 
first : loads the user_id
second : when a user adds a new record the user_records will auto take the value from  $user->id
third : users can see only there records
 
dont forget to include user_records in the add_fields
 
hope this can help a bit

Woz_Mann
  • profile picture
  • Member

Posted 25 October 2013 - 12:50 PM

Thanks Robert,

 

I am already using Ion_Auth, so your solution is great. Thanks!