public function indexAction() { $categories = Categories::find("is_actived=1"); $this->logger->info('INDEX'); $products = []; $categoryId = $this->request->getQuery("cid", "int"); #$categoryId = $this->dispatcher->getParam("cid"); $subcatId = $this->request->getQuery("sid", "int"); if (!$categoryId) { $categoryId = 1; } $category = Categories::findFirst($categoryId); if ($subcatId) { $query = Products::query()->where("is_available=1"); $query->andWhere("sub_category_id={$subcatId}"); $query->andWhere("status='Approved'"); $products = $query->execute(); } else { $query = Products::query()->where("is_available=1"); $query->andWhere("category_id={$categoryId}"); $query->andWhere("status='Approved'"); $products = $query->execute(); } $subcats = SubCategories::find("category_id={$categoryId}"); $this->view->categories = $categories; $this->view->subcats = $subcats; $this->view->currentCategory = $category; $this->view->products = $products; }
echo $form->field($model, 'price')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'Ingredients')->textarea(['rows' => 6]); ?> <?php echo $form->field($model, 'created')->textInput(); ?> <?php echo $form->field($model, 'updated')->textInput(); ?> <?php $listData = ArrayHelper::map(Categories::find()->all(), 'id', 'name'); ?> <?php echo $form->field($model, 'category_id')->dropDownList($listData, ['prompt' => 'Select...']); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end();
/** * Lists all Categories models. * @return mixed */ public function actionIndex() { $dataProvider = new ActiveDataProvider(['query' => Categories::find()]); return $this->render('index', ['dataProvider' => $dataProvider]); }