Skip to content

Commit

Permalink
Adding desired traits to base model class
Browse files Browse the repository at this point in the history
  • Loading branch information
motin committed Feb 23, 2015
1 parent c267a25 commit 492fcb9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
11 changes: 11 additions & 0 deletions fullModel/FullModelCode.php
Expand Up @@ -6,6 +6,7 @@ class FullModelCode extends ModelCode
{
public $tables;
public $baseClass = 'CActiveRecord';
public $baseClassTraits = '';
public $messageCatalog = 'model';
public $generateModel = true;

Expand All @@ -31,10 +32,19 @@ public function rules()
'pattern' => '/^[a-zA-Z_][\w.]*$/',
'message' => '{attribute} should only contain word characters.'
),
array('baseClassTraits', 'match', 'pattern'=>'/^[a-zA-Z_\\\\][\w\\\\,]*$/', 'message'=>'{attribute} should only contain word characters, commas and backslashes.'),
array('baseClassTraits', 'safe'),
)
);
}

public function attributeLabels()
{
return array_merge(parent::attributeLabels(), array(
'baseClassTraits'=>'Base Class Traits',
));
}

public function prepare()
{
parent::prepare();
Expand Down Expand Up @@ -72,6 +82,7 @@ public function prepare()
$params = array(
'tableName' => $schema === '' ? $tableName : $schema . '.' . $tableName,
'modelClass' => $className,
'baseClassTraits' => $this->baseClassTraits,
'columns' => $table->columns,
'labels' => $this->generateLabels($table),
'rules' => $this->generateRules($table),
Expand Down
8 changes: 8 additions & 0 deletions fullModel/templates/default/basemodel.php
Expand Up @@ -57,6 +57,14 @@
abstract class <?php echo 'Base' . $modelClass; ?> extends <?php echo $this->baseClass."\n"; ?>
{
<?php
if (!empty($this->baseClassTraits)) {
echo "\n";
foreach(explode(",", $this->baseClassTraits) as $traitName) {
echo ' use '.$traitName.';' . "\n";
}
}
?>
<?php
if(!empty($enum)){
?>
/**
Expand Down
8 changes: 8 additions & 0 deletions fullModel/views/index.php
Expand Up @@ -137,6 +137,14 @@
</div>
<?php echo $form->error($model, 'baseClass'); ?>
</div>
<div class="row sticky">
<?php echo $form->labelEx($model, 'baseClassTraits'); ?>
<?php echo $form->textField($model, 'baseClassTraits', array('size' => 65)); ?>
<div class="tooltip">
Comma-separated list of traits for base class to use.
</div>
<?php echo $form->error($model, 'baseClassTraits'); ?>
</div>
<div class="row sticky">
<?php echo $form->labelEx($model, 'modelPath'); ?>
<?php echo $form->textField($model, 'modelPath', array('size' => 65)); ?>
Expand Down

0 comments on commit 492fcb9

Please sign in to comment.