public function addSuccess($param) { if ($param['resourceId'] && $param['model']) { $nameExploded = explode('_', $param['resourceId']); $nameExploded = array_map('ucfirst', $nameExploded); $controllerName = $nameExploded[count($nameExploded) - 1]; unset($nameExploded[count($nameExploded) - 1]); $ds = DIRECTORY_SEPARATOR; $path = APPLICATION_PATH . $ds . 'modules' . $ds . $this->getRequest()->getModuleName() . $ds . 'controllers' . (($pathAdd = implode($ds, $nameExploded)) ? $ds . $pathAdd : ''); $fileName = $controllerName . 'Controller.php'; $controllerName = ucfirst($this->getRequest()->getModuleName()) . '_' . (($filePrefix = implode('_', $nameExploded)) ? $filePrefix . '_' : '') . $controllerName . 'Controller'; $class_file = new Zend_CodeGenerator_Php_Class(array('name' => $controllerName, 'extendedclass' => 'Z_Admin_Controller_Datacontrol_Abstract')); Z_Fs::create_file($path . $ds . $fileName, "<?\n" . $class_file->generate()); } }
/** * Генерирует класс модели * @param string $className * Название класса (без префикса) * @param string $tableName * Название таблицы в БД * @param array $params * Параметры для переопределения настроек по умолчанию * @return string */ public static function generate($className, $tableName = NULL, $params = array()) { if (strpos($className, 'z_') === 0 && Z_Auth::getInstance()->getUser()->getRole() == 'root') { $path_prefix = APPLICATION_PATH . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'library' . DIRECTORY_SEPARATOR . 'Z' . DIRECTORY_SEPARATOR . 'Model'; self::$_classPrefix = isset($params['prefixz']) ? $params['prefixz'] : self::$_classPrefixZ; } else { $path_prefix = APPLICATION_PATH . DIRECTORY_SEPARATOR . 'models'; self::$_classPrefix = isset($params['prefix']) ? $params['prefix'] : self::$_classPrefix; } if ($tableName == NULL) { $tableName = strtolower($className); } $className = explode('_', $className); $className = array_map('ucfirst', $className); $path = $className; unset($path[count($path) - 1]); $path = implode(DIRECTORY_SEPARATOR, $path); $filename = $className[count($className) - 1] . '.php'; $className = implode('_', $className); $filepath = $path_prefix . DIRECTORY_SEPARATOR . $path; $generator = new Zend_CodeGenerator_Php_Class(); $generator->setName(self::$_classPrefix . $className)->setExtendedClass(self::$_extendedClass)->setProperty(array('name' => '_name', 'visibility' => 'protected', 'defaultValue' => $tableName)); Z_Fs::create_file($filepath . DIRECTORY_SEPARATOR . $filename, "<?\n" . $generator->generate()); }