summaryrefslogtreecommitdiff
path: root/framework/gii/generators/module
diff options
context:
space:
mode:
authorPatrick Seeger <pseeger@ccwn.org>2012-04-13 23:11:05 +0200
committerPatrick Seeger <pseeger@ccwn.org>2012-04-13 23:11:05 +0200
commit341cc4dd9c53ffbfb863e026dd58549c1082c7a7 (patch)
tree1bbbed20313bafb9b063b6b4d894fe580d8b000f /framework/gii/generators/module
yii-framework 1.1.10 hinzugefügtHEADmaster
Diffstat (limited to 'framework/gii/generators/module')
-rw-r--r--framework/gii/generators/module/ModuleCode.php91
-rw-r--r--framework/gii/generators/module/ModuleGenerator.php6
-rw-r--r--framework/gii/generators/module/templates/default/components/.yii0
-rw-r--r--framework/gii/generators/module/templates/default/controllers/DefaultController.php9
-rw-r--r--framework/gii/generators/module/templates/default/messages/.yii0
-rw-r--r--framework/gii/generators/module/templates/default/models/.yii0
-rw-r--r--framework/gii/generators/module/templates/default/module.php28
-rw-r--r--framework/gii/generators/module/templates/default/views/default/index.php15
-rw-r--r--framework/gii/generators/module/templates/default/views/layouts/.yii0
-rw-r--r--framework/gii/generators/module/views/index.php19
10 files changed, 168 insertions, 0 deletions
diff --git a/framework/gii/generators/module/ModuleCode.php b/framework/gii/generators/module/ModuleCode.php
new file mode 100644
index 0000000..4fb90f0
--- /dev/null
+++ b/framework/gii/generators/module/ModuleCode.php
@@ -0,0 +1,91 @@
+<?php
+
+class ModuleCode extends CCodeModel
+{
+ public $moduleID;
+
+ public function rules()
+ {
+ return array_merge(parent::rules(), array(
+ array('moduleID', 'filter', 'filter'=>'trim'),
+ array('moduleID', 'required'),
+ array('moduleID', 'match', 'pattern'=>'/^\w+$/', 'message'=>'{attribute} should only contain word characters.'),
+ ));
+ }
+
+ public function attributeLabels()
+ {
+ return array_merge(parent::attributeLabels(), array(
+ 'moduleID'=>'Module ID',
+ ));
+ }
+
+ public function successMessage()
+ {
+ if(Yii::app()->hasModule($this->moduleID))
+ return 'The module has been generated successfully. You may '.CHtml::link('try it now', Yii::app()->createUrl($this->moduleID), array('target'=>'_blank')).'.';
+
+ $output=<<<EOD
+<p>The module has been generated successfully.</p>
+<p>To access the module, you need to modify the application configuration as follows:</p>
+EOD;
+ $code=<<<EOD
+<?php
+return array(
+ 'modules'=>array(
+ '{$this->moduleID}',
+ ),
+ ......
+);
+EOD;
+
+ return $output.highlight_string($code,true);
+ }
+
+ public function prepare()
+ {
+ $this->files=array();
+ $templatePath=$this->templatePath;
+ $modulePath=$this->modulePath;
+ $moduleTemplateFile=$templatePath.DIRECTORY_SEPARATOR.'module.php';
+
+ $this->files[]=new CCodeFile(
+ $modulePath.'/'.$this->moduleClass.'.php',
+ $this->render($moduleTemplateFile)
+ );
+
+ $files=CFileHelper::findFiles($templatePath,array(
+ 'exclude'=>array('.svn'),
+ ));
+
+ foreach($files as $file)
+ {
+ if($file!==$moduleTemplateFile)
+ {
+ if(CFileHelper::getExtension($file)==='php')
+ $content=$this->render($file);
+ else if(basename($file)==='.yii') // an empty directory
+ {
+ $file=dirname($file);
+ $content=null;
+ }
+ else
+ $content=file_get_contents($file);
+ $this->files[]=new CCodeFile(
+ $modulePath.substr($file,strlen($templatePath)),
+ $content
+ );
+ }
+ }
+ }
+
+ public function getModuleClass()
+ {
+ return ucfirst($this->moduleID).'Module';
+ }
+
+ public function getModulePath()
+ {
+ return Yii::app()->modulePath.DIRECTORY_SEPARATOR.$this->moduleID;
+ }
+} \ No newline at end of file
diff --git a/framework/gii/generators/module/ModuleGenerator.php b/framework/gii/generators/module/ModuleGenerator.php
new file mode 100644
index 0000000..c1ba1b6
--- /dev/null
+++ b/framework/gii/generators/module/ModuleGenerator.php
@@ -0,0 +1,6 @@
+<?php
+
+class ModuleGenerator extends CCodeGenerator
+{
+ public $codeModel='gii.generators.module.ModuleCode';
+} \ No newline at end of file
diff --git a/framework/gii/generators/module/templates/default/components/.yii b/framework/gii/generators/module/templates/default/components/.yii
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/framework/gii/generators/module/templates/default/components/.yii
diff --git a/framework/gii/generators/module/templates/default/controllers/DefaultController.php b/framework/gii/generators/module/templates/default/controllers/DefaultController.php
new file mode 100644
index 0000000..1936819
--- /dev/null
+++ b/framework/gii/generators/module/templates/default/controllers/DefaultController.php
@@ -0,0 +1,9 @@
+<?php echo "<?php\n"; ?>
+
+class DefaultController extends Controller
+{
+ public function actionIndex()
+ {
+ $this->render('index');
+ }
+} \ No newline at end of file
diff --git a/framework/gii/generators/module/templates/default/messages/.yii b/framework/gii/generators/module/templates/default/messages/.yii
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/framework/gii/generators/module/templates/default/messages/.yii
diff --git a/framework/gii/generators/module/templates/default/models/.yii b/framework/gii/generators/module/templates/default/models/.yii
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/framework/gii/generators/module/templates/default/models/.yii
diff --git a/framework/gii/generators/module/templates/default/module.php b/framework/gii/generators/module/templates/default/module.php
new file mode 100644
index 0000000..b0d98d0
--- /dev/null
+++ b/framework/gii/generators/module/templates/default/module.php
@@ -0,0 +1,28 @@
+<?php echo "<?php\n"; ?>
+
+class <?php echo $this->moduleClass; ?> extends CWebModule
+{
+ public function init()
+ {
+ // this method is called when the module is being created
+ // you may place code here to customize the module or the application
+
+ // import the module-level models and components
+ $this->setImport(array(
+ '<?php echo $this->moduleID; ?>.models.*',
+ '<?php echo $this->moduleID; ?>.components.*',
+ ));
+ }
+
+ public function beforeControllerAction($controller, $action)
+ {
+ if(parent::beforeControllerAction($controller, $action))
+ {
+ // this method is called before any module controller action is performed
+ // you may place customized code here
+ return true;
+ }
+ else
+ return false;
+ }
+}
diff --git a/framework/gii/generators/module/templates/default/views/default/index.php b/framework/gii/generators/module/templates/default/views/default/index.php
new file mode 100644
index 0000000..3ee8a6e
--- /dev/null
+++ b/framework/gii/generators/module/templates/default/views/default/index.php
@@ -0,0 +1,15 @@
+<?php echo "<?php\n"; ?>
+$this->breadcrumbs=array(
+ $this->module->id,
+);
+?>
+<h1><?php echo "<?php"; ?> echo $this->uniqueId . '/' . $this->action->id; ?></h1>
+
+<p>
+This is the view content for action "<?php echo "<?php"; ?> echo $this->action->id; ?>".
+The action belongs to the controller "<?php echo "<?php"; ?> echo get_class($this); ?>"
+in the "<?php echo "<?php"; ?> echo $this->module->id; ?>" module.
+</p>
+<p>
+You may customize this page by editing <tt><?php echo "<?php"; ?> echo __FILE__; ?></tt>
+</p> \ No newline at end of file
diff --git a/framework/gii/generators/module/templates/default/views/layouts/.yii b/framework/gii/generators/module/templates/default/views/layouts/.yii
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/framework/gii/generators/module/templates/default/views/layouts/.yii
diff --git a/framework/gii/generators/module/views/index.php b/framework/gii/generators/module/views/index.php
new file mode 100644
index 0000000..711e7e7
--- /dev/null
+++ b/framework/gii/generators/module/views/index.php
@@ -0,0 +1,19 @@
+<h1>Module Generator</h1>
+
+<p>This generator helps you to generate the skeleton code needed by a Yii module.</p>
+
+<?php $form=$this->beginWidget('CCodeForm', array('model'=>$model)); ?>
+
+ <div class="row">
+ <?php echo $form->labelEx($model,'moduleID'); ?>
+ <?php echo $form->textField($model,'moduleID',array('size'=>65)); ?>
+ <div class="tooltip">
+ Module ID is case-sensitive. It should only contain word characters.
+ The generated module class will be named after the module ID.
+ For example, a module ID <code>forum</code> will generate the module class
+ <code>ForumModule</code>.
+ </div>
+ <?php echo $form->error($model,'moduleID'); ?>
+ </div>
+
+<?php $this->endWidget(); ?>