public function actionCreateAction($id, $p = null) { $id = str_replace('/', '\\', $id); $arr = explode('\\', $id); $file = ''; $c = ''; $a = ''; $fileView = ''; if (count($arr) == 3) { $m = $arr[0]; $c = ucfirst($arr[1]); $c1 = strtolower($arr[1]); $a = ucfirst($arr[2]); $a1 = strtolower($a); $file = \Yii::getAlias("@app/modules/{$m}/controllers/{$c}Controller.php"); $fileView = \Yii::getAlias("@app/modules/{$m}/views/{$c1}/{$a1}.php"); } elseif (count($arr) == 2) { $c = ucfirst($arr[0]); $c1 = strtolower($arr[0]); $a = ucfirst($arr[1]); $a1 = strtolower($a); $file = \Yii::getAlias("@app/controllers/{$c}Controller.php"); $fileView = \Yii::getAlias("@app/views/{$c1}/{$a1}.php"); } else { } if (file_exists($file)) { $content = trim(file_get_contents($file)); if (strpos($content, "action" . $a . "(") === false) { $code = $this->getActionTemplate($a, explode(",", $p)); $new = preg_replace("/}\$/", $code . "\n}", $content); file_put_contents($file, $new); } if (!file_exists($fileView)) { $codeFile = new CodeFile($fileView, "<?php \n //{$c}/{$a}"); $codeFile->save(); } } }