You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
<?php
namespace api\controllers;
use yii\filters\auth\HttpBearerAuth; use yii\helpers\ArrayHelper; use yii\rest\ActiveController;
/** * @author iron * @email weiriron@gmail.com */ class GoodsController extends CommonController { public $modelClass = 'goods\models\ars\Goods';
public function actions() { $action = parent::actions(); unset($action['delete']); $action['index'] = [ 'class' => 'yii\rest\IndexAction', 'modelClass' => $this->modelClass, 'dataFilter' => $this->getFilter() ]; return $action; }
protected function getFilter() { $keyword = \Yii::$app->request->getBodyParam('keyword'); $category = \Yii::$app->request->getBodyParam('category'); $data = \Yii::$app->request->getBodyParams(); $data['user'] = true; \Yii::$app->request->setBodyParams($data); if ($keyword) { $data['name'] = ['like' => $keyword]; } if ($category) { $data['cat_id'] = $category; } $filter = ['class' => 'yii\data\ActiveDataFilter', 'filter' => $data, 'searchModel' => ['class' => 'antgoods\goods\models\searchs\GoodsSearch']]; return $filter; } }
|