Search code examples
permissionsfuelphp

check access permission in fuelphp


I am new to fuelphp, please help me with this problem. Currently, in users_permissions table I have this row:

id  area    permission  description actions user_id created_at  updated_at
1   member  detail                              1       0           0

Below is the written code in the controller

if (\Auth::has_access('member.detail'))
    $data['temp'] = "yeah";
else
    $data['temp'] = "no";

What I am trying to do is to give the access member.detail to user with id 1. But the result is always equals to "no".


Solution

  • You missed defining the relation.

    The permissions table just defines the permissions, the area, permission, and a possible array of valid actions. Before this takes effect, you have to assign this permission to something. This might be a user (direct assigned permission), or a group or a role to which the user is assigned. These are all many-to-many relations.

    So assuming your user has id 1, you need an entry in the users_user_permissions "relation|junction|through" table, relating the two records:

    id  user_id  perms_id actions
    1         1         1
    

    Now flush your auth cache, so the users effective rights are re-calculated, and it should work.