Added new (clean) yii boilerplate
This commit is contained in:
94
framework/gii/generators/module/ModuleCode.php
Normal file
94
framework/gii/generators/module/ModuleCode.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?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',
|
||||
'.gitignore'
|
||||
),
|
||||
));
|
||||
|
||||
foreach($files as $file)
|
||||
{
|
||||
if($file!==$moduleTemplateFile)
|
||||
{
|
||||
if(CFileHelper::getExtension($file)==='php')
|
||||
$content=$this->render($file);
|
||||
elseif(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;
|
||||
}
|
||||
}
|
||||
6
framework/gii/generators/module/ModuleGenerator.php
Normal file
6
framework/gii/generators/module/ModuleGenerator.php
Normal file
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
class ModuleGenerator extends CCodeGenerator
|
||||
{
|
||||
public $codeModel='gii.generators.module.ModuleCode';
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php echo "<?php\n"; ?>
|
||||
|
||||
class DefaultController extends Controller
|
||||
{
|
||||
public function actionIndex()
|
||||
{
|
||||
$this->render('index');
|
||||
}
|
||||
}
|
||||
28
framework/gii/generators/module/templates/default/module.php
Normal file
28
framework/gii/generators/module/templates/default/module.php
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php echo "<?php\n"; ?>
|
||||
/* @var $this DefaultController */
|
||||
|
||||
$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>
|
||||
19
framework/gii/generators/module/views/index.php
Normal file
19
framework/gii/generators/module/views/index.php
Normal file
@@ -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(); ?>
|
||||
Reference in New Issue
Block a user