public function editModelAction($module, $modelName) { $path = Modules::getModulePath($module) . '/models/' . $modelName . '.php'; if (!file_exists($path)) { Tools::redirect('/admin/modules/edit/' . $module, 'Модель ' . $modelName . ' не найдена', 'danger'); } include_once Modules::getModulePath($module) . '/models/' . $modelName . '.php'; $modelFullName = $module . '\\' . $modelName; $model = new $modelFullName(); if (filter_input(INPUT_POST, 'codeName') && filter_input(INPUT_POST, 'name')) { $this->modules->generateModel($module, filter_input(INPUT_POST, 'name'), filter_input(INPUT_POST, 'codeName'), ['cols' => $_POST['cols']]); Tools::redirect('/admin/modules/editor/' . $module, 'Модель ' . filter_input(INPUT_POST, 'codeName') . ' была сохранена'); } $this->view->page(['content' => 'modelEditor', 'data' => compact('module', 'modelName', 'modelFullName', 'model')]); }
public function addActionToController($module, $type, $controller, $url) { $modulePath = Module::getModulePath($module); $path = Modules::getModulePath($module) . '/' . $type . '/' . $controller . '.php'; $class = CodeGenerator::parseClass($path); $class->addMethod($url . 'Action'); $controllerCode = "<?php\n\n" . $class->generate(); Tools::createDir(pathinfo($path, PATHINFO_DIRNAME)); file_put_contents($path, $controllerCode); $config = Config::custom($modulePath . '/generatorHash.php'); $config[$type . '/' . $module . 'Controller.php'] = md5($controllerCode); Config::save($modulePath . '/generatorHash.php', $config); }
<?php $table = new Ui\Table(); $table->name = 'Страницы'; $table->setCols(['Адрес', 'Операции']); $table->addButton(['href' => "/admin/modules/createControllerMethod/{$module}/{$type}/{$controller}", 'text' => 'Создать']); $class = CodeGenerator::parseClass(Modules::getModulePath($module) . '/' . $type . '/' . $controller . '.php'); foreach ($class->methods as $method) { $name = str_replace('Action', '', $method->name); $table->addRow([$name, ['class' => 'actionTd', 'html' => '<a class="btn btn-xs btn-success" href="/admin/modules/editControllerMethod/' . $module . '/' . $type . '/' . $controller . '/' . $name . '"><i class="glyphicon glyphicon-edit"></i></a>' . ' <a class="btn btn-xs btn-danger" href="/admin/modules/delControllerMethod/' . $module . '/' . $type . '/' . $controller . '/' . $name . '"><i class="glyphicon glyphicon-remove"></i></a>']]); } $table->draw();