function actionGetcontrollersandactions() { $controllerlist = []; if ($handle = opendir('../backend/controllers')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." && substr($file, strrpos($file, '.') - 10) == 'Controller.php') { $controllerlist[] = $file; } } closedir($handle); } asort($controllerlist); $fulllist = []; foreach ($controllerlist as $controller) { $handle = fopen('../backend/controllers/' . $controller, "r"); if ($handle) { while (($line = fgets($handle)) !== false) { if (preg_match('/function action(.*?)\\(/', $line, $display)) { if (strlen($display[1]) > 2) { $fulllist[substr($controller, 0, -14)][] = strtolower($display[1]); } } } } fclose($handle); } $model = new RoleAction(); $model->deleteAll(); if (!empty($fulllist)) { foreach ($fulllist as $key => $value) { foreach ($value as $k => $v) { $ActionModel = new RoleAction(); $ActionModel->module_name = 'TestModule'; $ActionModel->controller_name = $key; $ActionModel->action_name = $v; $ActionModel->save(); } } } }