Как создать фильтр в таблице админки по названию продукта?
Сейчас имеется следующий вид modules/admin/views/product/index.php:
Код: Выделить всё
<?php
use yii\helpers\Html;
use yii\grid\GridView;
/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'Products';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="product-index">
<h1><?= Html::encode($this->title) ?></h1>
<p>
<?= Html::a('Create Product', ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
// ['class' => 'yii\grid\SerialColumn'],
'id',
// 'category_id',
[
'attribute' => 'category_id',
'value' => function($data){
return $data->category->name;
},
],
'name',
'alias',
// 'content:ntext',
'price',
//'keywords',
//'description',
//'img',
// 'hit',
[
'attribute' => 'hit',
'value' => function($data){
return !$data->hit ? '<span class="text-danger">Нет</span>' : '<span class="text-success">Да</span>';
},
'format' => 'html',
],
//'new',
//'sale',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
</div>
Код: Выделить всё
<?php
namespace app\modules\admin\models;
use Yii;
/**
* This is the model class for table "product".
*
* @property int $id
* @property int $category_id
* @property string $name
* @property string|null $alias
* @property string|null $content
* @property float $price
* @property string|null $keywords
* @property string|null $description
* @property string|null $img
* @property string $hit
* @property string $new
* @property string $sale
*/
class Product extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'product';
}
public function getCategory(){
return $this->hasOne(Category::className(), ['id' => 'category_id']);
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['category_id', 'name'], 'required'],
[['category_id'], 'integer'],
[['content', 'hit', 'new', 'sale'], 'string'],
[['price'], 'number'],
[['name', 'alias', 'keywords', 'description', 'img'], 'string', 'max' => 255],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID товара',
'category_id' => 'Категория',
'name' => 'Наименование',
'alias' => 'Транслитерация(Алиас)',
'content' => 'Контент',
'price' => 'Цена',
'keywords' => 'Ключевые слова',
'description' => 'Описание',
'img' => 'Img',
'hit' => 'Хит',
'new' => 'New',
'sale' => 'Sale',
];
}
}
Спасибо заранее всем кто просмотрел. )))