/** * Creates a new RoleAction model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { if (!$this->is_access('roleaction/create')) { Yii::$app->session->setFlash('error', $this->errorInfo); return $this->redirect($this->redirectUrl); } $model = new RoleAction(); if ($model->load(Yii::$app->request->post()) && $model->save()) { Yii::$app->session->setFlash('success', '添加成功'); return $this->redirect(['index']); } else { Yii::$app->view->params['meta_title'] = '添加角色节点'; $actionTop = $model->getActionTwoItem(); return $this->render('create', ['model' => $model, 'actionTop' => $actionTop]); } }
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(); } } } }