public function actionIndex($id)
{
$searchModel = new ProductPitSearch();
// $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
// $dataProvider = $searchModel->search(['ProductPitSearch' => Yii::$app->request->queryParams]);
$parentCat = CategoryPit::find()
->where(['parent_id' => $id])
->andWhere(['status' => CategoryPit::STATUS_CATEGORY_ON])
->asArray()
->all();
$result = [];
foreach ($parentCat as $cat) {
$result[] = $cat['id'];
}
if ($id == isset($cat['parent_id'])) {
$query = ProductPit::getAllProteinProduct($result);
} else {
$query = ProductPit::getProductByStatus($id);
}
$dataProvider = new ActiveDataProvider([
'query' => $query,
'pagination' => [
'pageSize' => 40,
],
]);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
[
'ProductPitSearch' => [
'brand_id' => '86'
]
]
[
'id' => '23'
'ProductPitSearch' => [
'brand_id' => '86'
]
]
Что кроется под "не работает"?- имеется виду то что выбрал нужную категорию (Яичный протеин) такая ссылка
http://sportpit.alex-sport.com.ua/category/index?id=23
вывело все правильноhttp://sportpit.alex-sport.com.ua/category/index?id=23&ProductPitSearch%5Bbrand_id%5D=86
[
'id' => '23'
'ProductPitSearch' => [
'brand_id' => '86'
]
]
----------------
<?php
use yii\helpers\Html;
use yii\widgets\ListView;
use yii\widgets\Pjax;
/* @var $this yii\web\View */
/* @var $searchModel common\models\ProductPitSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = Yii::t('app', 'Product Pits');
$this->params['breadcrumbs'][] = $this->title;
\yii\helpers\VarDumper::dump($_GET, 11, 1);
?>
<div class="product-pit-index">
<div style="float: left;margin-right: 40px">
<?php echo $this->render('_search', ['model' => $searchModel]); ?>
</div>
<div style="float: left">
<?php echo $this->render('_sort', ['model' => $searchModel]); ?>
</div>
<br>
<?php Pjax::begin(['formSelector' => '#form_sort_item_category']) ?>
<div style="margin-top: 50px;">
<?= ListView::widget([
'dataProvider' => $dataProvider,
'layout' => "{summary}\n<div class=\"items\">{items}</div>\n{pager}",
'summary' => '',
'itemOptions' => ['class' => 'item'],
'itemView' => function ($model, $key, $index, $widget) {
return $this->render('grid', ['model' => $model]);
},
]) ?>
</div>
<?php Pjax::end(); ?>
</div>
'action' => ['index','id'=>$some_id],
, и работает. http://sportpit.alex-sport.com.ua/category/index?id=23&ProductPitSearch%5Bbrand_id%5D=86
: без фильтра адресная строка была без фильтраhttp://sportpit.alex-sport.com.ua/category/index?id=23
[
'ProductPitSearch' => [
'brand_id' => '86'
]
]
$query->andFilterWhere([
'category_id' => $this->id,
'brand_id' => $this->brand_id,
'country_id' => $this->country_id,
'packing' => $this->packing,
]);
$id = Yii::$app->request->queryParams;
$query = ProductPit::find()
->where(['category_id' => $id])
->andWhere(['status' => ProductPit::STATUS_PRODUCT_ON]);
ProductPit::getProductByStatus($id);
, разъясните пожалуйста?? <?php
namespace common\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use yii\helpers\VarDumper;
/**
* ProductPitSearch represents the model behind the search form about `common\models\ProductPit`.
*/
class ProductPitSearch extends ProductPit
{
public $sort;
public $id; Вы за это имеете виду
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id', 'status', 'new', 'hit', 'sale', 'stock', 'top_sales', 'top_ten', 'category_id', 'img_id', 'gallery_id', 'brand_id', 'country_id', 'quantity', 'quantity_product', 'packing', 'availability', 'created_at', 'updated_at'], 'integer'],
[['title', 'content', 'composition', 'vendor_code', 'seo_keywords', 'seo_description'], 'safe'],
//[['old_price', 'price'], 'number'],
[['old_price', 'price'], 'string'],
];
}
/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = ProductPit::find(); Что тут надо делать
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
// grid filtering conditions
$query->andFilterWhere([
'brand_id' => $this->brand_id,
'country_id' => $this->country_id,
'packing' => $this->packing,
]);
if ($this->price) {
$range = explode(',', $this->price);
$query->andFilterWhere([
'and',
['>', 'price', $range[0]],
['<', 'price', $range[1]]
]);
}
return $dataProvider;
}
}