diff --git a/apps/advanced/backend/views/site/login.php b/apps/advanced/backend/views/site/login.php index b37bb6b..0c16570 100644 --- a/apps/advanced/backend/views/site/login.php +++ b/apps/advanced/backend/views/site/login.php @@ -21,7 +21,7 @@ $this->params['breadcrumbs'][] = $this->title; field($model, 'username'); ?> field($model, 'password')->passwordInput(); ?> field($model, 'rememberMe')->checkbox(); ?> -
- * return array_merge(parent::attributeLabels(), array( - * ...labels for the child class attributes... - * )); - *- * @return array the attribute labels - */ - public function attributeLabels() - { - return array( - 'template' => 'Code Template', - ); - } - - /** - * Returns a list of code templates that are required. - * Derived classes usually should override this method. - * @return array list of code templates that are required. They should be file paths - * relative to {@link templatePath}. - */ - public function requiredTemplates() - { - return array(); - } - - /** * Saves the generated code into files. */ - public function save() + public function save($files, $answers = array()) { $result = true; - foreach ($this->files as $file) { + foreach ($files as $file) { if ($this->confirmed($file)) { $result = $file->save() && $result; } @@ -259,59 +120,25 @@ class Generator extends Model } /** - * Returns the message to be displayed when the newly generated code is saved successfully. - * Child classes should override this method if the message needs to be customized. - * @return string the message to be displayed when the newly generated code is saved successfully. - */ - public function successMessage() - { - return 'The code has been generated successfully.'; - } - - /** - * Returns the message to be displayed when some error occurred during code file saving. - * Child classes should override this method if the message needs to be customized. - * @return string the message to be displayed when some error occurred during code file saving. - */ - public function errorMessage() - { - return 'There was some error when generating the code. Please check the following messages.'; - } - - /** - * Returns a list of available code templates (name=>directory). - * This method simply returns the {@link CCodeGenerator::templates} property value. - * @return array a list of available code templates (name=>directory). - */ - public function getTemplates() - { - return Yii::app()->controller->templates; - } - - /** * @return string the directory that contains the template files. - * @throws CHttpException if {@link templates} is empty or template selection is invalid + * @throws InvalidConfigException if {@link templates} is empty or template selection is invalid */ public function getTemplatePath() { - $templates = $this->getTemplates(); - if (isset($templates[$this->template])) { - return $templates[$this->template]; - } elseif (empty($templates)) { - throw new CHttpException(500, 'No templates are available.'); + if (isset($this->templates[$this->template])) { + return $this->templates[$this->template]; } else { - throw new CHttpException(500, 'Invalid template selection.'); + throw new InvalidConfigException("Unknown template: {$this->template}"); } - } /** - * @param CCodeFile $file whether the code file should be saved + * @param CodeFile $file whether the code file should be saved * @return bool whether the confirmation is found in {@link answers} with appropriate {@link operation} */ public function confirmed($file) { - return $this->answers === null && $file->operation === CCodeFile::OP_NEW + return $this->answers === null && $file->operation === CodeFile::OP_NEW || is_array($this->answers) && isset($this->answers[md5($file->path)]); } @@ -320,24 +147,12 @@ class Generator extends Model * This method is manly used in {@link generate} to generate code. * @param string $templateFile the code template file path * @param array $_params_ a set of parameters to be extracted and made available in the code template - * @throws CException is template file does not exist * @return string the generated code */ - public function render($templateFile, $_params_ = null) + public function render($templateFile, $params = array()) { - if (!is_file($templateFile)) { - throw new CException("The template file '$templateFile' does not exist."); - } - - if (is_array($_params_)) { - extract($_params_, EXTR_PREFIX_SAME, 'params'); - } else { - $params = $_params_; - } - ob_start(); - ob_implicit_flush(false); - require($templateFile); - return ob_get_clean(); + $view = new View; + return $view->renderFile($templateFile, $params, $this); } /** @@ -349,9 +164,9 @@ class Generator extends Model foreach ($this->files as $file) { if ($file->error !== null) { $output .= "generating {$file->relativePath}
order
generates OrderController.php
order-item
generates OrderItemController.php
admin/user
generates UserController.php
within the admin
module.order
generates OrderController.php
order-item
generates OrderItemController.php
admin/user
generates UserController.php
within the admin
module.Code File | +Action | ++ operation !== CodeFile::OP_SKIP) { + $count++; + } + } + if ($count > 1) { + echo ''; + } + ?> + | +
---|---|---|
+ getRelativePath()), array('code', 'file' => $i), array('class' => 'view-code', 'rel' => $file->path)); ?> + operation === CodeFile::OP_OVERWRITE): ?> + ( $i), array('class' => 'view-code', 'rel' => $file->path)); ?>) + + | ++ operation === CodeFile::OP_SKIP) { + echo 'unchanged'; + } else { + echo $file->operation; + } + ?> + | ++ operation === CodeFile::OP_SKIP) { + echo ' '; + } else { + $key = md5($file->path); + echo Html::checkBox("answers[$key]"); + } + ?> + | +
Start the fun with the following code generators:
getDescription(); ?>
-getUrl(), array('class' => 'btn btn-default')); ?>
+$id), array('class' => 'btn btn-default')); ?>
getDescription(); ?>
- renderForm(); ?> + +