Skip to content

Commit d218d7e

Browse files
committed
Add Controller Sub-Folder Access Support
Enables codeigniter-restserver to restrict access to controllers that are in sub-folder paths. Useful for custom routers that allow arbitrary controller sub folder organization PLUS compatability with Codeigniter 3 controller sub-folders.
1 parent 26fb607 commit d218d7e

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

application/libraries/REST_Controller.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,12 +1513,17 @@ protected function _check_access()
15131513
return true;
15141514
}
15151515

1516-
$controller = explode('/', $this->uri->uri_string());
1516+
// Fetch controller based on path and controller name
1517+
$controller = implode( '/', array($this->router->fetch_directory(), $this->router->fetch_class()) );
1518+
1519+
// Remove any double slashes for safety
1520+
$controller = str_replace('//', '/', $controller);
15171521

1522+
// Build access table query
15181523
$this->rest->db->select();
15191524
$this->rest->db->where('key', $this->rest->key);
1520-
$this->rest->db->where('controller', $controller[0]);
1521-
1525+
$this->rest->db->where('controller', $controller);
1526+
15221527
$query = $this->rest->db->get(config_item('rest_access_table'));
15231528

15241529
if ($query->num_rows > 0) {

0 commit comments

Comments
 (0)