Всем привет! Не могу понять, как в Rest контроллере сделать findBySql? Опыта с Rest не много, прошу помощи)
Нужно вернуть немного измененные данные из базы на основе запроса
"SELECT *, ST_AsGeoJSON(geom) AS geo_json FROM projects"
Rest Controller:
<?php namespace frontend\controllers;
use yii\rest\ActiveController;
use app\models\Project;
use yii\data\ActiveDataProvider;
class ProjectController extends ActiveController
{
public $modelClass = Project::class;
public function behaviors() {
return array_merge(parent::behaviors(), [
'corsFilter' => [
'class' => \yii\filters\Cors::class,
'cors' => [
'Origin' => ['http://localhost:3000'],
'Access-Control-Request-Method' => ['POST', 'GET'],
'Access-Control-Allow-Credentials' => true,
'Access-Control-Max-Age' => 3600,
],
],
]);
}
public function actions()
{
$actions = parent::actions();
unset($actions['create'], $actions['update'], $actions['delete']);
$actions['index'] = [
'class' => 'yii\rest\IndexAction',
'modelClass' => $this->modelClass,
'prepareDataProvider' => function () {
$model = new $this->modelClass;
$query = $model::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
'pagination' => false,
]);
return $dataProvider;
},
];
return $actions;
}
}