From d7c1010e201a8ddccd3040e2a5d2c96ecd8e507a Mon Sep 17 00:00:00 2001 From: "qiang.xue" Date: Mon, 5 Apr 2010 02:43:41 +0000 Subject: [PATCH] --- framework/gii/generators/model/ModelCode.php | 16 +++++++----- .../model/templates/default/model.php | 26 ++++++++++++------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/framework/gii/generators/model/ModelCode.php b/framework/gii/generators/model/ModelCode.php index 44b8b5d8b..91a93d67e 100644 --- a/framework/gii/generators/model/ModelCode.php +++ b/framework/gii/generators/model/ModelCode.php @@ -53,9 +53,18 @@ class ModelCode extends CCodeModel $this->files=array(); $templatePath=$this->templatePath; + $params=array( + 'tableName'=>$this->removePrefix($this->tableName), + 'modelClass'=>$this->modelClass, + 'columns'=>$this->getColumns(), + 'labels'=>$this->getLabels(), + 'rules'=>$this->getRules(), + 'relations'=>$this->getRelations(), + ); + $this->files[]=new CCodeFile( Yii::getPathOfAlias($this->modelPath).'/'.$this->modelClass.'.php', - $this->render($templatePath.'/model.php') + $this->render($templatePath.'/model.php', $params) ); } @@ -161,11 +170,6 @@ class ModelCode extends CCodeModel return isset($relations[$this->modelClass]) ? $relations[$this->modelClass] : array(); } - public function getTableNameWithoutPrefix() - { - return $this->removePrefix($this->tableName); - } - protected function removePrefix($tableName,$addBrackets=true) { $prefix=$this->tablePrefix!='' ? $this->tablePrefix : Yii::app()->db->tablePrefix; diff --git a/framework/gii/generators/model/templates/default/model.php b/framework/gii/generators/model/templates/default/model.php index 8c10260c3..936407909 100644 --- a/framework/gii/generators/model/templates/default/model.php +++ b/framework/gii/generators/model/templates/default/model.php @@ -2,18 +2,24 @@ /** * This is the template for generating the model class of a specified table. * - $this: the CrudCode object + * - $tableName: the table name for this class (prefix is already removed if necessary) + * - $modelClass: the model class name + * - $columns: list of table columns (name=>CDbColumnSchema) + * - $labels: list of attribute labels (name=>label) + * - $rules: list of validation rules + * - $relations: list of relations (name=>relation declaration) */ ?> /** - * This is the model class for table "tableNameWithoutPrefix; ?>". + * This is the model class for table "". */ -class modelClass; ?> extends baseClass."\n"; ?> +class extends baseClass."\n"; ?> { /** - * The followings are the available columns in table 'tableNameWithoutPrefix; ?>': -getColumns() as $column): ?> + * The followings are the available columns in table '': + * @var type.' $'.$column->name."\n"; ?> */ @@ -32,7 +38,7 @@ class modelClass; ?> extends baseClass."\n"; */ public function tableName() { - return 'tableNameWithoutPrefix; ?>'; + return ''; } /** @@ -43,12 +49,12 @@ class modelClass; ?> extends baseClass."\n"; // NOTE: you should only define rules for those attributes that // will receive user inputs. return array( -getRules() as $rule): ?> + // The following rule is used by search(). // Please remove those attributes that should not be searched. - array('getColumns())); ?>', 'safe', 'on'=>'search'), + array('', 'safe', 'on'=>'search'), ); } @@ -60,7 +66,7 @@ class modelClass; ?> extends baseClass."\n"; // NOTE: you may need to adjust the relation name and the related // class name for the relations automatically generated below. return array( -getRelations() as $name=>$relation): ?> +$relation): ?> $relation,\n"; ?> ); @@ -72,7 +78,7 @@ class modelClass; ?> extends baseClass."\n"; public function attributeLabels() { return array( -getLabels() as $name=>$label): ?> +$label): ?> '$label',\n"; ?> ); @@ -90,7 +96,7 @@ class modelClass; ?> extends baseClass."\n"; $criteria=new CDbCriteria; getColumns() as $name=>$column) +foreach($columns as $name=>$column) { if($column->type==='string') {