![]() |
Help Needed: How to build an HTML table with Codeigniter 4 and Shield Permissions - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Addins (https://forum.codeigniter.com/forumdisplay.php?fid=34) +--- Thread: Help Needed: How to build an HTML table with Codeigniter 4 and Shield Permissions (/showthread.php?tid=87702) |
Help Needed: How to build an HTML table with Codeigniter 4 and Shield Permissions - DeanE10 - 05-22-2023 I posted a topic on Stack but still seeking an answer so I am trying here too... Link to Post Using Codeigniter 4.3.3, Shield 1.0.0-beta.5 and MySQL I am sure I am over complicating this... I would like to build an html table using the auth_permissions_users table and 2 left nav tables sidebar_modules and sidebar_modules_sub. By default, Shield likes to use Group.Permission stored in the auth_permissions_users table IE: admin.useredit, admin.useradd etc... I will be using a traditional method of controller.permission thus the reason for the other tables. For the mast part I have this working correctly though it seems there should be an easier way... I built a function inside array_helper.php in the helpers folder. the function will split the controller.permission, group them by controller, then build the table based on what it finds. Though I said it is working, I have 2 issues: Using this table as column order reference: ![]() #1 - I would like to have 5 rows as shown in the table IE: | Controller | Create | Read | Update | Delete | This means we have to fill in any blanks if the permission is not provided to the user. IE: If the user only has read permissions - shown in image below #2 - Need to figure out how to sort them in a way they will come out exactly correct in the table since they are not always entered into the database table in the same order. IE: | Controller | Create | Read | Update | Delete | Data from Shield using $user->getPermissions(); PHP Code: Array ********************************************************* What I have done so far ********************************************************* If I use asort() and ksort(), I can order the array which will sort the permissions alphabetically, however if I only have one of the 4 permissions, then I have to inject the missing permission. That's when the array once again is out of order... example data before injecting missing values into the array. You can see in activitylogs I am missing Create, Update, Delete. Same with admin permission PHP Code: Array I created a function in an array_helper.php file to create a table "buildPermissionsTable()". I tried to comment the code as much as possible to explain what I am doing. array_helper.php PHP Code: if (!function_exists('buildPermissionsTable')) { This is how the table looks now, notice they are not in the correct order as Create-Read-Update-Delete. it should properly align with the column header: | Controller | Create | Read | Update | Delete | ![]() |