File: /home/emblazeone/www/master-template/frontend/controllers/ProductsController.php
<?php
namespace frontend\controllers;
use backend\modules\categories\models\Category;
use backend\modules\exercises\models\Exercises;
use backend\modules\pages\models\Pages;
use backend\modules\pages\models\PagesSites;
use backend\modules\products\models\Products;
use common\models\Identity;
use frontend\actions\GetProfileImageAction;
use wbp\images\models\Image;
use Yii;
use yii\data\ActiveDataProvider;
use yii\filters\AccessControl;
use yii\filters\VerbFilter;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
/**
* Site controller
*/
class ProductsController extends BaseController
{
public function actionProduct($href){
$product = $this->site->getProducts()->andWhere(['href'=>$href, 'status'=>Products::STATUS_ACTIVE])
->one();
if(!$product){
throw new NotFoundHttpException('Page Not Found.');
}
return $this->render($product->template, ['product'=>$product]);
}
public function actionIndex(){
$dataProvider=new ActiveDataProvider([
'query'=>$this->site->getProducts()->andWhere(['status'=>Products::STATUS_ACTIVE])
]);
return $this->render('index', ['dataProvider'=>$dataProvider]);
}
public function actionCategory($href){
$category = $this->site->getCategories()->andWhere(['href'=>$href, 'status'=>Category::STATUS_ACTIVE])
->one();
if(!$category){
throw new NotFoundHttpException('Page Not Found.');
}
$dataProvider=new ActiveDataProvider([
'query'=>$category->getProducts()->andWhere(['status'=>Products::STATUS_ACTIVE])
]);
return $this->render('category', ['category'=>$category, 'dataProvider'=>$dataProvider]);
}
}