Код: Выделить всё
public function actionView($id){
$rang = Yii::$app->request->get('rang');
$rang2 = Yii::$app->request->get('rang2');
//
// $id2 = Yii::$app->request->get('id2');
//
//
// $range = explode(" ", $id2);
// $left=$range[0];
//
// $right= (!isset($range[2]))?$right=0:$right=$range[2];
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
if ($rang = Yii::$app->request->get('id2')) {
$result = explode(":", $rang);
$range = [];
foreach($result as $value) {
$range[] = trim($value, " ");
}
return [
'left' => $range[0],
'right' => $range[1],
'success' => true,
];
}
}
// return $this->redirect(['category', 'id' => $id]);
//debug($range);
// $min2 = Product::find()->where(['category_id' => $id, ])->min('price');
// $min2 = Product::find()->with('category')->where(['id' => $id])
$rangeres = Product::find()
->select(['name'])
->where(['between', 'price', 1000, 50000])
->indexBy('name')
->column();
// if( !Yii::$app->request->isAjax ){
// return $this->redirect(Yii::$app->request->referrer);
//}
//debug($range);
// if (\Yii::$app->request->isAjax){
// $range = explode(" ", $id2);
// $left=$range[0];
// $right=$range[2];
//return \yii\helpers\Json::encode($range);
//}
// return $this->redirect(['index']);
// $rang = !$rang ? 1 : $rang;
// $id = Yii::$app->request->get('id');
$category = Category::findOne($id);
$query2 = Brand::find()->where(['category_id' => $id]);
if(empty($category))
throw new \yii\web\HttpException(404, 'Такой категории нет');
// $products = Product::find()->where(['category_id' => $id])->all();
$query = Product::find()->where(['category_id' => $id]);
$pages = new Pagination(['totalCount' => $query->count(), 'pageSize' => 3, 'forcePageParam' => false, 'pageSizeParam' => false]);
$products = $query->offset($pages->offset)->limit($pages->limit)->all();
$min = Product::find()->where(['category_id' => $id])->min('price');
$max = Product::find()->where(['category_id' => $id])->max('price');
$brands = $query2->orderBy('name')->all();
$this->setMeta('Автозапчасти | ' . $category->name, $category->keywords, $category->description);
return $this->render('view', compact('products', 'pages', 'category','min','max', 'brands','rang2','id', 'rangeres','left' ));