From 220db270cfd3efd0b6f89197de615f8354c18c70 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Wed, 25 Sep 2013 21:20:58 -0400 Subject: [PATCH] Improved crud generator. --- framework/yii/gii/generators/crud/templates/views/index.php | 8 +++----- framework/yii/gii/generators/crud/templates/views/view.php | 4 ++-- framework/yii/grid/DataColumn.php | 11 +++++++++-- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/framework/yii/gii/generators/crud/templates/views/index.php b/framework/yii/gii/generators/crud/templates/views/index.php index df76581..1de548a 100644 --- a/framework/yii/gii/generators/crud/templates/views/index.php +++ b/framework/yii/gii/generators/crud/templates/views/index.php @@ -30,13 +30,11 @@ $this->params['breadcrumbs'][] = $this->title;

echo Html::encode($this->title); ?>

- echo $this->render('_search', array('model' => $searchModel)); ?> + indexWidgetType === 'grid' ? ' //' : ''); ?> echo $this->render('_search', array('model' => $searchModel)); ?> -
- -
+

echo Html::a('Create modelClass); ?>', array('create'), array('class' => 'btn btn-danger')); ?> -

+

indexWidgetType === 'grid'): ?> echo GridView::widget(array( diff --git a/framework/yii/gii/generators/crud/templates/views/view.php b/framework/yii/gii/generators/crud/templates/views/view.php index a3b6cad..d25a851 100644 --- a/framework/yii/gii/generators/crud/templates/views/view.php +++ b/framework/yii/gii/generators/crud/templates/views/view.php @@ -29,14 +29,14 @@ $this->params['breadcrumbs'][] = $this->title;

echo Html::encode($this->title); ?>

-
+

echo Html::a('Update', array('update', ), array('class' => 'btn btn-danger')); ?> echo Html::a('Delete', array('delete', ), array( 'class' => 'btn btn-danger', 'data-confirm' => Yii::t('app', 'Are you sure to delete this item?'), 'data-method' => 'post', )); ?> -

+

echo DetailView::widget(array( 'model' => $model, diff --git a/framework/yii/grid/DataColumn.php b/framework/yii/grid/DataColumn.php index 295dece..4ebbb8f 100644 --- a/framework/yii/grid/DataColumn.php +++ b/framework/yii/grid/DataColumn.php @@ -68,6 +68,12 @@ class DataColumn extends Column * - If you don't want a filter for this data column, set this value to be false. */ public $filter; + /** + * @var array the HTML attributes for the filter input fields. This property is used in combination with + * the [[filter]] property. When [[filter]] is not set or is an array, this property will be used to + * render the HTML attributes for the generated filter input fields. + */ + public $filterInputOptions = array('class' => 'form-control'); protected function renderHeaderCellContent() @@ -111,9 +117,10 @@ class DataColumn extends Column return $this->filter; } elseif ($this->filter !== false && $this->grid->filterModel instanceof Model && $this->attribute !== null) { if (is_array($this->filter)) { - return Html::activeDropDownList($this->grid->filterModel, $this->attribute, $this->filter, array('prompt' => '')); + $options = array_merge(array('prompt' => ''), $this->filterInputOptions); + return Html::activeDropDownList($this->grid->filterModel, $this->attribute, $this->filter, $options); } else { - return Html::activeTextInput($this->grid->filterModel, $this->attribute); + return Html::activeTextInput($this->grid->filterModel, $this->attribute, $this->filterInputOptions); } } else { return parent::renderFilterCellContent();