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.
 
 
 

47 lines
1.1 KiB

<?php
namespace api\controllers;
use Yii;
/**
* @author iron
* @email weiriron@gmail.com
*/
class GoodsController extends CommonController
{
public $modelClass = 'backend\modules\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');
$array = [];
if ($keyword) {
$array['name'] = ['like' => $keyword];
}
if ($category) {
$array['cat_id'] = $category;
}
if (empty($array)) {
return null;
}
return ['class' => 'yii\data\ActiveDataFilter',
'filter' => $array,
'searchModel' => ['class' => 'backend\modules\goods\models\searchs\GoodsSearch']];
}
}