Пример #1
0
<?php

$modGen = new yii\gii\generators\model\Generator();
$className = $modGen->generateClassName($tableName);
$title = yii\helpers\Inflector::pluralize($className);
echo "<?php\n";
?>
use app\models\<?php 
echo $className;
?>
; 
use yii\helpers\Html;
<?php 
echo "?>";
?>

<div class="panel panel-primary">
    <div class="panel-heading">
        <h3 class="panel-title"><i class="glyphicon glyphicon-list"></i>Manage <?php 
echo $title;
?>
</h3>        
    </div>
    <table id="<?php 
echo $tableName;
?>
_grid">
        <tr>
            <?php 
echo "<?php \${$tableName}Mod = new {$className}; ?>\n";
?>
Пример #2
0
 public function generateKartikField($attribute)
 {
     $tableSchema = $this->getTableSchema();
     $column = $tableSchema->columns[$attribute];
     $placeHolder = '';
     $hint = '';
     //        return $column->phpType;
     //        return $column->size;
     if ($column->phpType === 'boolean') {
         return "['type'=>Form::INPUT_CHECKBOX]";
     } elseif ($column->type === 'smallint' && $column->size == 1) {
         return "['type'=>Form::INPUT_CHECKBOX]";
     } elseif ($column->type === 'text') {
         return "['type'=>Form::INPUT_TEXTAREA, 'options'=>['placeholder'=>'{$placeHolder}']]";
     } elseif ($column->type === 'date') {
         return "['type'=>Form::INPUT_WIDGET, " . "'widgetClass'=>'\\kartik\\widgets\\DatePicker'," . "'hint'=>'{$hint}'," . "'options' => ['pluginOptions' => ['format' => 'yyyy-mm-dd', 'autoclose'=>true, 'todayHighlight' => true]]]";
     } elseif ($column->type === 'datetime') {
         return "['type'=>Form::INPUT_WIDGET, " . "'widgetClass'=>'\\kartik\\widgets\\DateTimePicker'," . "'hint'=>'{$hint}'," . "'options' => ['pluginOptions'=>['format' => 'yyyy-mm-dd h:i', 'autoclose'=>true, 'todayHighlight' => true]]]";
     } elseif ($column->type === 'integer' && $this->getForeignKeyInfo($attribute) !== null) {
         $foreignKeyInfo = $this->getForeignKeyInfo($attribute);
         $foreignTable = $foreignKeyInfo['foreignTable'];
         $foreignKey = $foreignKeyInfo['foreignKey'];
         $modGen = new yii\gii\generators\model\Generator();
         $className = $modGen->generateClassName($foreignTable);
         $foreignFieldName = $this->getNameAttributeOfTable($foreignTable);
         return "['type'=>Form::INPUT_DROPDOWN_LIST, " . "'items' => ArrayHelper::map({$className}::find()->orderBy('{$foreignFieldName}')->asArray()->all(), '{$foreignKey}', '{$foreignFieldName}')," . "'options'=>['prompt' => 'Select...', 'placeholder'=>'{$placeHolder}']]";
     } else {
         return "['type'=>Form::INPUT_TEXT, 'options'=>['placeholder'=>'{$placeHolder}']]";
     }
 }