summaryrefslogtreecommitdiff
path: root/framework/gii/generators/crud
diff options
context:
space:
mode:
Diffstat (limited to 'framework/gii/generators/crud')
-rw-r--r--framework/gii/generators/crud/CrudCode.php248
-rw-r--r--framework/gii/generators/crud/CrudGenerator.php6
-rw-r--r--framework/gii/generators/crud/templates/default/_form.php39
-rw-r--r--framework/gii/generators/crud/templates/default/_search.php32
-rw-r--r--framework/gii/generators/crud/templates/default/_view.php26
-rw-r--r--framework/gii/generators/crud/templates/default/admin.php70
-rw-r--r--framework/gii/generators/crud/templates/default/controller.php183
-rw-r--r--framework/gii/generators/crud/templates/default/create.php24
-rw-r--r--framework/gii/generators/crud/templates/default/index.php26
-rw-r--r--framework/gii/generators/crud/templates/default/update.php28
-rw-r--r--framework/gii/generators/crud/templates/default/view.php36
-rw-r--r--framework/gii/generators/crud/views/index.php64
12 files changed, 782 insertions, 0 deletions
diff --git a/framework/gii/generators/crud/CrudCode.php b/framework/gii/generators/crud/CrudCode.php
new file mode 100644
index 0000000..b08eb6d
--- /dev/null
+++ b/framework/gii/generators/crud/CrudCode.php
@@ -0,0 +1,248 @@
+<?php
+
+class CrudCode extends CCodeModel
+{
+ public $model;
+ public $controller;
+ public $baseControllerClass='Controller';
+
+ private $_modelClass;
+ private $_table;
+
+ public function rules()
+ {
+ return array_merge(parent::rules(), array(
+ array('model, controller', 'filter', 'filter'=>'trim'),
+ array('model, controller, baseControllerClass', 'required'),
+ array('model', 'match', 'pattern'=>'/^\w+[\w+\\.]*$/', 'message'=>'{attribute} should only contain word characters and dots.'),
+ array('controller', 'match', 'pattern'=>'/^\w+[\w+\\/]*$/', 'message'=>'{attribute} should only contain word characters and slashes.'),
+ array('baseControllerClass', 'match', 'pattern'=>'/^[a-zA-Z_]\w*$/', 'message'=>'{attribute} should only contain word characters.'),
+ array('baseControllerClass', 'validateReservedWord', 'skipOnError'=>true),
+ array('model', 'validateModel'),
+ array('baseControllerClass', 'sticky'),
+ ));
+ }
+
+ public function attributeLabels()
+ {
+ return array_merge(parent::attributeLabels(), array(
+ 'model'=>'Model Class',
+ 'controller'=>'Controller ID',
+ 'baseControllerClass'=>'Base Controller Class',
+ ));
+ }
+
+ public function requiredTemplates()
+ {
+ return array(
+ 'controller.php',
+ );
+ }
+
+ public function init()
+ {
+ if(Yii::app()->db===null)
+ throw new CHttpException(500,'An active "db" connection is required to run this generator.');
+ parent::init();
+ }
+
+ public function successMessage()
+ {
+ $link=CHtml::link('try it now', Yii::app()->createUrl($this->controller), array('target'=>'_blank'));
+ return "The controller has been generated successfully. You may $link.";
+ }
+
+ public function validateModel($attribute,$params)
+ {
+ if($this->hasErrors('model'))
+ return;
+ $class=@Yii::import($this->model,true);
+ if(!is_string($class) || !$this->classExists($class))
+ $this->addError('model', "Class '{$this->model}' does not exist or has syntax error.");
+ else if(!is_subclass_of($class,'CActiveRecord'))
+ $this->addError('model', "'{$this->model}' must extend from CActiveRecord.");
+ else
+ {
+ $table=CActiveRecord::model($class)->tableSchema;
+ if($table->primaryKey===null)
+ $this->addError('model',"Table '{$table->name}' does not have a primary key.");
+ else if(is_array($table->primaryKey))
+ $this->addError('model',"Table '{$table->name}' has a composite primary key which is not supported by crud generator.");
+ else
+ {
+ $this->_modelClass=$class;
+ $this->_table=$table;
+ }
+ }
+ }
+
+ public function prepare()
+ {
+ $this->files=array();
+ $templatePath=$this->templatePath;
+ $controllerTemplateFile=$templatePath.DIRECTORY_SEPARATOR.'controller.php';
+
+ $this->files[]=new CCodeFile(
+ $this->controllerFile,
+ $this->render($controllerTemplateFile)
+ );
+
+ $files=scandir($templatePath);
+ foreach($files as $file)
+ {
+ if(is_file($templatePath.'/'.$file) && CFileHelper::getExtension($file)==='php' && $file!=='controller.php')
+ {
+ $this->files[]=new CCodeFile(
+ $this->viewPath.DIRECTORY_SEPARATOR.$file,
+ $this->render($templatePath.'/'.$file)
+ );
+ }
+ }
+ }
+
+ public function getModelClass()
+ {
+ return $this->_modelClass;
+ }
+
+ public function getControllerClass()
+ {
+ if(($pos=strrpos($this->controller,'/'))!==false)
+ return ucfirst(substr($this->controller,$pos+1)).'Controller';
+ else
+ return ucfirst($this->controller).'Controller';
+ }
+
+ public function getModule()
+ {
+ if(($pos=strpos($this->controller,'/'))!==false)
+ {
+ $id=substr($this->controller,0,$pos);
+ if(($module=Yii::app()->getModule($id))!==null)
+ return $module;
+ }
+ return Yii::app();
+ }
+
+ public function getControllerID()
+ {
+ if($this->getModule()!==Yii::app())
+ $id=substr($this->controller,strpos($this->controller,'/')+1);
+ else
+ $id=$this->controller;
+ if(($pos=strrpos($id,'/'))!==false)
+ $id[$pos+1]=strtolower($id[$pos+1]);
+ else
+ $id[0]=strtolower($id[0]);
+ return $id;
+ }
+
+ public function getUniqueControllerID()
+ {
+ $id=$this->controller;
+ if(($pos=strrpos($id,'/'))!==false)
+ $id[$pos+1]=strtolower($id[$pos+1]);
+ else
+ $id[0]=strtolower($id[0]);
+ return $id;
+ }
+
+ public function getControllerFile()
+ {
+ $module=$this->getModule();
+ $id=$this->getControllerID();
+ if(($pos=strrpos($id,'/'))!==false)
+ $id[$pos+1]=strtoupper($id[$pos+1]);
+ else
+ $id[0]=strtoupper($id[0]);
+ return $module->getControllerPath().'/'.$id.'Controller.php';
+ }
+
+ public function getViewPath()
+ {
+ return $this->getModule()->getViewPath().'/'.$this->getControllerID();
+ }
+
+ public function getTableSchema()
+ {
+ return $this->_table;
+ }
+
+ public function generateInputLabel($modelClass,$column)
+ {
+ return "CHtml::activeLabelEx(\$model,'{$column->name}')";
+ }
+
+ public function generateInputField($modelClass,$column)
+ {
+ if($column->type==='boolean')
+ return "CHtml::activeCheckBox(\$model,'{$column->name}')";
+ else if(stripos($column->dbType,'text')!==false)
+ return "CHtml::activeTextArea(\$model,'{$column->name}',array('rows'=>6, 'cols'=>50))";
+ else
+ {
+ if(preg_match('/^(password|pass|passwd|passcode)$/i',$column->name))
+ $inputField='activePasswordField';
+ else
+ $inputField='activeTextField';
+
+ if($column->type!=='string' || $column->size===null)
+ return "CHtml::{$inputField}(\$model,'{$column->name}')";
+ else
+ {
+ if(($size=$maxLength=$column->size)>60)
+ $size=60;
+ return "CHtml::{$inputField}(\$model,'{$column->name}',array('size'=>$size,'maxlength'=>$maxLength))";
+ }
+ }
+ }
+
+ public function generateActiveLabel($modelClass,$column)
+ {
+ return "\$form->labelEx(\$model,'{$column->name}')";
+ }
+
+ public function generateActiveField($modelClass,$column)
+ {
+ if($column->type==='boolean')
+ return "\$form->checkBox(\$model,'{$column->name}')";
+ else if(stripos($column->dbType,'text')!==false)
+ return "\$form->textArea(\$model,'{$column->name}',array('rows'=>6, 'cols'=>50))";
+ else
+ {
+ if(preg_match('/^(password|pass|passwd|passcode)$/i',$column->name))
+ $inputField='passwordField';
+ else
+ $inputField='textField';
+
+ if($column->type!=='string' || $column->size===null)
+ return "\$form->{$inputField}(\$model,'{$column->name}')";
+ else
+ {
+ if(($size=$maxLength=$column->size)>60)
+ $size=60;
+ return "\$form->{$inputField}(\$model,'{$column->name}',array('size'=>$size,'maxlength'=>$maxLength))";
+ }
+ }
+ }
+
+ public function guessNameColumn($columns)
+ {
+ foreach($columns as $column)
+ {
+ if(!strcasecmp($column->name,'name'))
+ return $column->name;
+ }
+ foreach($columns as $column)
+ {
+ if(!strcasecmp($column->name,'title'))
+ return $column->name;
+ }
+ foreach($columns as $column)
+ {
+ if($column->isPrimaryKey)
+ return $column->name;
+ }
+ return 'id';
+ }
+} \ No newline at end of file
diff --git a/framework/gii/generators/crud/CrudGenerator.php b/framework/gii/generators/crud/CrudGenerator.php
new file mode 100644
index 0000000..790e073
--- /dev/null
+++ b/framework/gii/generators/crud/CrudGenerator.php
@@ -0,0 +1,6 @@
+<?php
+
+class CrudGenerator extends CCodeGenerator
+{
+ public $codeModel='gii.generators.crud.CrudCode';
+} \ No newline at end of file
diff --git a/framework/gii/generators/crud/templates/default/_form.php b/framework/gii/generators/crud/templates/default/_form.php
new file mode 100644
index 0000000..6f86788
--- /dev/null
+++ b/framework/gii/generators/crud/templates/default/_form.php
@@ -0,0 +1,39 @@
+<?php
+/**
+ * The following variables are available in this template:
+ * - $this: the CrudCode object
+ */
+?>
+<div class="form">
+
+<?php echo "<?php \$form=\$this->beginWidget('CActiveForm', array(
+ 'id'=>'".$this->class2id($this->modelClass)."-form',
+ 'enableAjaxValidation'=>false,
+)); ?>\n"; ?>
+
+ <p class="note">Fields with <span class="required">*</span> are required.</p>
+
+ <?php echo "<?php echo \$form->errorSummary(\$model); ?>\n"; ?>
+
+<?php
+foreach($this->tableSchema->columns as $column)
+{
+ if($column->autoIncrement)
+ continue;
+?>
+ <div class="row">
+ <?php echo "<?php echo ".$this->generateActiveLabel($this->modelClass,$column)."; ?>\n"; ?>
+ <?php echo "<?php echo ".$this->generateActiveField($this->modelClass,$column)."; ?>\n"; ?>
+ <?php echo "<?php echo \$form->error(\$model,'{$column->name}'); ?>\n"; ?>
+ </div>
+
+<?php
+}
+?>
+ <div class="row buttons">
+ <?php echo "<?php echo CHtml::submitButton(\$model->isNewRecord ? 'Create' : 'Save'); ?>\n"; ?>
+ </div>
+
+<?php echo "<?php \$this->endWidget(); ?>\n"; ?>
+
+</div><!-- form --> \ No newline at end of file
diff --git a/framework/gii/generators/crud/templates/default/_search.php b/framework/gii/generators/crud/templates/default/_search.php
new file mode 100644
index 0000000..91c4fe8
--- /dev/null
+++ b/framework/gii/generators/crud/templates/default/_search.php
@@ -0,0 +1,32 @@
+<?php
+/**
+ * The following variables are available in this template:
+ * - $this: the CrudCode object
+ */
+?>
+<div class="wide form">
+
+<?php echo "<?php \$form=\$this->beginWidget('CActiveForm', array(
+ 'action'=>Yii::app()->createUrl(\$this->route),
+ 'method'=>'get',
+)); ?>\n"; ?>
+
+<?php foreach($this->tableSchema->columns as $column): ?>
+<?php
+ $field=$this->generateInputField($this->modelClass,$column);
+ if(strpos($field,'password')!==false)
+ continue;
+?>
+ <div class="row">
+ <?php echo "<?php echo \$form->label(\$model,'{$column->name}'); ?>\n"; ?>
+ <?php echo "<?php echo ".$this->generateActiveField($this->modelClass,$column)."; ?>\n"; ?>
+ </div>
+
+<?php endforeach; ?>
+ <div class="row buttons">
+ <?php echo "<?php echo CHtml::submitButton('Search'); ?>\n"; ?>
+ </div>
+
+<?php echo "<?php \$this->endWidget(); ?>\n"; ?>
+
+</div><!-- search-form --> \ No newline at end of file
diff --git a/framework/gii/generators/crud/templates/default/_view.php b/framework/gii/generators/crud/templates/default/_view.php
new file mode 100644
index 0000000..9c3529a
--- /dev/null
+++ b/framework/gii/generators/crud/templates/default/_view.php
@@ -0,0 +1,26 @@
+<?php
+/**
+ * The following variables are available in this template:
+ * - $this: the CrudCode object
+ */
+?>
+<div class="view">
+
+<?php
+echo "\t<b><?php echo CHtml::encode(\$data->getAttributeLabel('{$this->tableSchema->primaryKey}')); ?>:</b>\n";
+echo "\t<?php echo CHtml::link(CHtml::encode(\$data->{$this->tableSchema->primaryKey}), array('view', 'id'=>\$data->{$this->tableSchema->primaryKey})); ?>\n\t<br />\n\n";
+$count=0;
+foreach($this->tableSchema->columns as $column)
+{
+ if($column->isPrimaryKey)
+ continue;
+ if(++$count==7)
+ echo "\t<?php /*\n";
+ echo "\t<b><?php echo CHtml::encode(\$data->getAttributeLabel('{$column->name}')); ?>:</b>\n";
+ echo "\t<?php echo CHtml::encode(\$data->{$column->name}); ?>\n\t<br />\n\n";
+}
+if($count>=7)
+ echo "\t*/ ?>\n";
+?>
+
+</div> \ No newline at end of file
diff --git a/framework/gii/generators/crud/templates/default/admin.php b/framework/gii/generators/crud/templates/default/admin.php
new file mode 100644
index 0000000..cc060c2
--- /dev/null
+++ b/framework/gii/generators/crud/templates/default/admin.php
@@ -0,0 +1,70 @@
+<?php
+/**
+ * The following variables are available in this template:
+ * - $this: the CrudCode object
+ */
+?>
+<?php
+echo "<?php\n";
+$label=$this->pluralize($this->class2name($this->modelClass));
+echo "\$this->breadcrumbs=array(
+ '$label'=>array('index'),
+ 'Manage',
+);\n";
+?>
+
+$this->menu=array(
+ array('label'=>'List <?php echo $this->modelClass; ?>', 'url'=>array('index')),
+ array('label'=>'Create <?php echo $this->modelClass; ?>', 'url'=>array('create')),
+);
+
+Yii::app()->clientScript->registerScript('search', "
+$('.search-button').click(function(){
+ $('.search-form').toggle();
+ return false;
+});
+$('.search-form form').submit(function(){
+ $.fn.yiiGridView.update('<?php echo $this->class2id($this->modelClass); ?>-grid', {
+ data: $(this).serialize()
+ });
+ return false;
+});
+");
+?>
+
+<h1>Manage <?php echo $this->pluralize($this->class2name($this->modelClass)); ?></h1>
+
+<p>
+You may optionally enter a comparison operator (<b>&lt;</b>, <b>&lt;=</b>, <b>&gt;</b>, <b>&gt;=</b>, <b>&lt;&gt;</b>
+or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done.
+</p>
+
+<?php echo "<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>"; ?>
+
+<div class="search-form" style="display:none">
+<?php echo "<?php \$this->renderPartial('_search',array(
+ 'model'=>\$model,
+)); ?>\n"; ?>
+</div><!-- search-form -->
+
+<?php echo "<?php"; ?> $this->widget('zii.widgets.grid.CGridView', array(
+ 'id'=>'<?php echo $this->class2id($this->modelClass); ?>-grid',
+ 'dataProvider'=>$model->search(),
+ 'filter'=>$model,
+ 'columns'=>array(
+<?php
+$count=0;
+foreach($this->tableSchema->columns as $column)
+{
+ if(++$count==7)
+ echo "\t\t/*\n";
+ echo "\t\t'".$column->name."',\n";
+}
+if($count>=7)
+ echo "\t\t*/\n";
+?>
+ array(
+ 'class'=>'CButtonColumn',
+ ),
+ ),
+)); ?>
diff --git a/framework/gii/generators/crud/templates/default/controller.php b/framework/gii/generators/crud/templates/default/controller.php
new file mode 100644
index 0000000..56eb826
--- /dev/null
+++ b/framework/gii/generators/crud/templates/default/controller.php
@@ -0,0 +1,183 @@
+<?php
+/**
+ * This is the template for generating a controller class file for CRUD feature.
+ * The following variables are available in this template:
+ * - $this: the CrudCode object
+ */
+?>
+<?php echo "<?php\n"; ?>
+
+class <?php echo $this->controllerClass; ?> extends <?php echo $this->baseControllerClass."\n"; ?>
+{
+ /**
+ * @var string the default layout for the views. Defaults to '//layouts/column2', meaning
+ * using two-column layout. See 'protected/views/layouts/column2.php'.
+ */
+ public $layout='//layouts/column2';
+
+ /**
+ * @return array action filters
+ */
+ public function filters()
+ {
+ return array(
+ 'accessControl', // perform access control for CRUD operations
+ );
+ }
+
+ /**
+ * Specifies the access control rules.
+ * This method is used by the 'accessControl' filter.
+ * @return array access control rules
+ */
+ public function accessRules()
+ {
+ return array(
+ array('allow', // allow all users to perform 'index' and 'view' actions
+ 'actions'=>array('index','view'),
+ 'users'=>array('*'),
+ ),
+ array('allow', // allow authenticated user to perform 'create' and 'update' actions
+ 'actions'=>array('create','update'),
+ 'users'=>array('@'),
+ ),
+ array('allow', // allow admin user to perform 'admin' and 'delete' actions
+ 'actions'=>array('admin','delete'),
+ 'users'=>array('admin'),
+ ),
+ array('deny', // deny all users
+ 'users'=>array('*'),
+ ),
+ );
+ }
+
+ /**
+ * Displays a particular model.
+ * @param integer $id the ID of the model to be displayed
+ */
+ public function actionView($id)
+ {
+ $this->render('view',array(
+ 'model'=>$this->loadModel($id),
+ ));
+ }
+
+ /**
+ * Creates a new model.
+ * If creation is successful, the browser will be redirected to the 'view' page.
+ */
+ public function actionCreate()
+ {
+ $model=new <?php echo $this->modelClass; ?>;
+
+ // Uncomment the following line if AJAX validation is needed
+ // $this->performAjaxValidation($model);
+
+ if(isset($_POST['<?php echo $this->modelClass; ?>']))
+ {
+ $model->attributes=$_POST['<?php echo $this->modelClass; ?>'];
+ if($model->save())
+ $this->redirect(array('view','id'=>$model-><?php echo $this->tableSchema->primaryKey; ?>));
+ }
+
+ $this->render('create',array(
+ 'model'=>$model,
+ ));
+ }
+
+ /**
+ * Updates a particular model.
+ * If update is successful, the browser will be redirected to the 'view' page.
+ * @param integer $id the ID of the model to be updated
+ */
+ public function actionUpdate($id)
+ {
+ $model=$this->loadModel($id);
+
+ // Uncomment the following line if AJAX validation is needed
+ // $this->performAjaxValidation($model);
+
+ if(isset($_POST['<?php echo $this->modelClass; ?>']))
+ {
+ $model->attributes=$_POST['<?php echo $this->modelClass; ?>'];
+ if($model->save())
+ $this->redirect(array('view','id'=>$model-><?php echo $this->tableSchema->primaryKey; ?>));
+ }
+
+ $this->render('update',array(
+ 'model'=>$model,
+ ));
+ }
+
+ /**
+ * Deletes a particular model.
+ * If deletion is successful, the browser will be redirected to the 'admin' page.
+ * @param integer $id the ID of the model to be deleted
+ */
+ public function actionDelete($id)
+ {
+ if(Yii::app()->request->isPostRequest)
+ {
+ // we only allow deletion via POST request
+ $this->loadModel($id)->delete();
+
+ // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
+ if(!isset($_GET['ajax']))
+ $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
+ }
+ else
+ throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
+ }
+
+ /**
+ * Lists all models.
+ */
+ public function actionIndex()
+ {
+ $dataProvider=new CActiveDataProvider('<?php echo $this->modelClass; ?>');
+ $this->render('index',array(
+ 'dataProvider'=>$dataProvider,
+ ));
+ }
+
+ /**
+ * Manages all models.
+ */
+ public function actionAdmin()
+ {
+ $model=new <?php echo $this->modelClass; ?>('search');
+ $model->unsetAttributes(); // clear any default values
+ if(isset($_GET['<?php echo $this->modelClass; ?>']))
+ $model->attributes=$_GET['<?php echo $this->modelClass; ?>'];
+
+ $this->render('admin',array(
+ 'model'=>$model,
+ ));
+ }
+
+ /**
+ * Returns the data model based on the primary key given in the GET variable.
+ * If the data model is not found, an HTTP exception will be raised.
+ * @param integer the ID of the model to be loaded
+ */
+ public function loadModel($id)
+ {
+ $model=<?php echo $this->modelClass; ?>::model()->findByPk($id);
+ if($model===null)
+ throw new CHttpException(404,'The requested page does not exist.');
+ return $model;
+ }
+
+ /**
+ * Performs the AJAX validation.
+ * @param CModel the model to be validated
+ */
+ protected function performAjaxValidation($model)
+ {
+ if(isset($_POST['ajax']) && $_POST['ajax']==='<?php echo $this->class2id($this->modelClass); ?>-form')
+ {
+ echo CActiveForm::validate($model);
+ Yii::app()->end();
+ }
+ }
+}
diff --git a/framework/gii/generators/crud/templates/default/create.php b/framework/gii/generators/crud/templates/default/create.php
new file mode 100644
index 0000000..817a7f6
--- /dev/null
+++ b/framework/gii/generators/crud/templates/default/create.php
@@ -0,0 +1,24 @@
+<?php
+/**
+ * The following variables are available in this template:
+ * - $this: the CrudCode object
+ */
+?>
+<?php
+echo "<?php\n";
+$label=$this->pluralize($this->class2name($this->modelClass));
+echo "\$this->breadcrumbs=array(
+ '$label'=>array('index'),
+ 'Create',
+);\n";
+?>
+
+$this->menu=array(
+ array('label'=>'List <?php echo $this->modelClass; ?>', 'url'=>array('index')),
+ array('label'=>'Manage <?php echo $this->modelClass; ?>', 'url'=>array('admin')),
+);
+?>
+
+<h1>Create <?php echo $this->modelClass; ?></h1>
+
+<?php echo "<?php echo \$this->renderPartial('_form', array('model'=>\$model)); ?>"; ?>
diff --git a/framework/gii/generators/crud/templates/default/index.php b/framework/gii/generators/crud/templates/default/index.php
new file mode 100644
index 0000000..5bd1b0f
--- /dev/null
+++ b/framework/gii/generators/crud/templates/default/index.php
@@ -0,0 +1,26 @@
+<?php
+/**
+ * The following variables are available in this template:
+ * - $this: the CrudCode object
+ */
+?>
+<?php
+echo "<?php\n";
+$label=$this->pluralize($this->class2name($this->modelClass));
+echo "\$this->breadcrumbs=array(
+ '$label',
+);\n";
+?>
+
+$this->menu=array(
+ array('label'=>'Create <?php echo $this->modelClass; ?>', 'url'=>array('create')),
+ array('label'=>'Manage <?php echo $this->modelClass; ?>', 'url'=>array('admin')),
+);
+?>
+
+<h1><?php echo $label; ?></h1>
+
+<?php echo "<?php"; ?> $this->widget('zii.widgets.CListView', array(
+ 'dataProvider'=>$dataProvider,
+ 'itemView'=>'_view',
+)); ?>
diff --git a/framework/gii/generators/crud/templates/default/update.php b/framework/gii/generators/crud/templates/default/update.php
new file mode 100644
index 0000000..0004686
--- /dev/null
+++ b/framework/gii/generators/crud/templates/default/update.php
@@ -0,0 +1,28 @@
+<?php
+/**
+ * The following variables are available in this template:
+ * - $this: the CrudCode object
+ */
+?>
+<?php
+echo "<?php\n";
+$nameColumn=$this->guessNameColumn($this->tableSchema->columns);
+$label=$this->pluralize($this->class2name($this->modelClass));
+echo "\$this->breadcrumbs=array(
+ '$label'=>array('index'),
+ \$model->{$nameColumn}=>array('view','id'=>\$model->{$this->tableSchema->primaryKey}),
+ 'Update',
+);\n";
+?>
+
+$this->menu=array(
+ array('label'=>'List <?php echo $this->modelClass; ?>', 'url'=>array('index')),
+ array('label'=>'Create <?php echo $this->modelClass; ?>', 'url'=>array('create')),
+ array('label'=>'View <?php echo $this->modelClass; ?>', 'url'=>array('view', 'id'=>$model-><?php echo $this->tableSchema->primaryKey; ?>)),
+ array('label'=>'Manage <?php echo $this->modelClass; ?>', 'url'=>array('admin')),
+);
+?>
+
+<h1>Update <?php echo $this->modelClass." <?php echo \$model->{$this->tableSchema->primaryKey}; ?>"; ?></h1>
+
+<?php echo "<?php echo \$this->renderPartial('_form', array('model'=>\$model)); ?>"; ?> \ No newline at end of file
diff --git a/framework/gii/generators/crud/templates/default/view.php b/framework/gii/generators/crud/templates/default/view.php
new file mode 100644
index 0000000..b52004d
--- /dev/null
+++ b/framework/gii/generators/crud/templates/default/view.php
@@ -0,0 +1,36 @@
+<?php
+/**
+ * The following variables are available in this template:
+ * - $this: the CrudCode object
+ */
+?>
+<?php
+echo "<?php\n";
+$nameColumn=$this->guessNameColumn($this->tableSchema->columns);
+$label=$this->pluralize($this->class2name($this->modelClass));
+echo "\$this->breadcrumbs=array(
+ '$label'=>array('index'),
+ \$model->{$nameColumn},
+);\n";
+?>
+
+$this->menu=array(
+ array('label'=>'List <?php echo $this->modelClass; ?>', 'url'=>array('index')),
+ array('label'=>'Create <?php echo $this->modelClass; ?>', 'url'=>array('create')),
+ array('label'=>'Update <?php echo $this->modelClass; ?>', 'url'=>array('update', 'id'=>$model-><?php echo $this->tableSchema->primaryKey; ?>)),
+ array('label'=>'Delete <?php echo $this->modelClass; ?>', 'url'=>'#', 'linkOptions'=>array('submit'=>array('delete','id'=>$model-><?php echo $this->tableSchema->primaryKey; ?>),'confirm'=>'Are you sure you want to delete this item?')),
+ array('label'=>'Manage <?php echo $this->modelClass; ?>', 'url'=>array('admin')),
+);
+?>
+
+<h1>View <?php echo $this->modelClass." #<?php echo \$model->{$this->tableSchema->primaryKey}; ?>"; ?></h1>
+
+<?php echo "<?php"; ?> $this->widget('zii.widgets.CDetailView', array(
+ 'data'=>$model,
+ 'attributes'=>array(
+<?php
+foreach($this->tableSchema->columns as $column)
+ echo "\t\t'".$column->name."',\n";
+?>
+ ),
+)); ?>
diff --git a/framework/gii/generators/crud/views/index.php b/framework/gii/generators/crud/views/index.php
new file mode 100644
index 0000000..d7271dc
--- /dev/null
+++ b/framework/gii/generators/crud/views/index.php
@@ -0,0 +1,64 @@
+<?php
+$class=get_class($model);
+Yii::app()->clientScript->registerScript('gii.crud',"
+$('#{$class}_controller').change(function(){
+ $(this).data('changed',$(this).val()!='');
+});
+$('#{$class}_model').bind('keyup change', function(){
+ var controller=$('#{$class}_controller');
+ if(!controller.data('changed')) {
+ var id=new String($(this).val().match(/\\w*$/));
+ if(id.length>0)
+ id=id.substring(0,1).toLowerCase()+id.substring(1);
+ controller.val(id);
+ }
+});
+");
+?>
+<h1>Crud Generator</h1>
+
+<p>This generator generates a controller and views that implement CRUD operations for the specified data model.</p>
+
+<?php $form=$this->beginWidget('CCodeForm', array('model'=>$model)); ?>
+
+ <div class="row">
+ <?php echo $form->labelEx($model,'model'); ?>
+ <?php echo $form->textField($model,'model',array('size'=>65)); ?>
+ <div class="tooltip">
+ Model class is case-sensitive. It can be either a class name (e.g. <code>Post</code>)
+ or the path alias of the class file (e.g. <code>application.models.Post</code>).
+ Note that if the former, the class must be auto-loadable.
+ </div>
+ <?php echo $form->error($model,'model'); ?>
+ </div>
+
+ <div class="row">
+ <?php echo $form->labelEx($model,'controller'); ?>
+ <?php echo $form->textField($model,'controller',array('size'=>65)); ?>
+ <div class="tooltip">
+ Controller ID is case-sensitive. CRUD controllers are often named after
+ the model class name that they are dealing with. Below are some examples:
+ <ul>
+ <li><code>post</code> generates <code>PostController.php</code></li>
+ <li><code>postTag</code> generates <code>PostTagController.php</code></li>
+ <li><code>admin/user</code> generates <code>admin/UserController.php</code>.
+ If the application has an <code>admin</code> module enabled,
+ it will generate <code>UserController</code> (and other CRUD code)
+ within the module instead.
+ </li>
+ </ul>
+ </div>
+ <?php echo $form->error($model,'controller'); ?>
+ </div>
+
+ <div class="row sticky">
+ <?php echo $form->labelEx($model,'baseControllerClass'); ?>
+ <?php echo $form->textField($model,'baseControllerClass',array('size'=>65)); ?>
+ <div class="tooltip">
+ This is the class that the new CRUD controller class will extend from.
+ Please make sure the class exists and can be autoloaded.
+ </div>
+ <?php echo $form->error($model,'baseControllerClass'); ?>
+ </div>
+
+<?php $this->endWidget(); ?>