Closed ghassanhjr closed 2 years ago
$this->getPermissions() returns a multi-dimensional array(two levels ) where in_array can't find the permission name for example
Hi @ghassanhjr.
getPermissions() method of User entity returns array like
[ permission_id => permission_name, permission_id=> permission_name, ]
not a multi-dimentional array (two levels) as you said.
So return in_array(strtolower($permission), $this->getPermissions(), true);
code works well.
yes, you are correct, $this->permissions
or getPermissions()
, both return an array of other arrays that's why inside the method public function can(string $permission)
, can't return the correct answer, , it has a search function in_array(strtolower($permission), $this->getPermissions(), true);
, where in_array() function search only in one dimension, and it's always returning false
@ghassanhjr can you share some example output of getPermissions()
where this doesn't work? @manageruz shows a clear example of it not being a multi-dimensional array, and we have a test case for this (although not very robust): https://github.com/lonnieezell/myth-auth/blob/develop/tests/unit/UserEntityTest.php
there you are, the method where I can inside the permissions variable
method dumbing the permissions variable:
result in page body:
the result from the CodeIgniter :
You are clearly confusing something. Is sidebar is a user's permission? And there are two 'sidebar' permissions for one user? In your current database how many permissions you have (look at the auth_permissions database table)? Can you find there 'sidebar'? And attached photo doesn't look like var_dump function result. Can you show full content?
And show me var_dump($this->getPermissions()); die();
result instead of yours.
Before to do all above manipulations run php spark cache:clear command in terminal or manually delete cache files if there is one (cache files located in your_project_root/writable/cache . Delete all files except index.html)
https://github.com/lonnieezell/myth-auth/blob/0ab551af4cd97e675cb77e9f8b44b54c354b3daa/src/Entities/User.php#L227
$this->getPermissions() returns a multi-dimensional array(two levels ) where in_array can't find the permission name for example,
I suggest having a multi to multi-dimensional search for $permission for the returned value.