Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCategory()
 {
     return $this->hasOne(Categories::className(), ['id' => 'category_id']);
 }
Exemplo n.º 3
0
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();
 /**
  * Finds the Categories model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Categories the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Categories::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }