git config --global merge.conflictstyle diff3
Нашёл в контексте yiisoft/yii2#3635 Вашу разработку, пытаюсь соеденить с yii\rest\ActiveController
в меру понимания текущего кода ветки master
, т.к. доки написаны ещё для релиза.
Собственно, пока что потестить пробовал сделать простую модель и актив-контроллер на модуле пользователей
use hiqdev\hiart\ActiveRecord;
class RemoteUser extends ActiveRecord
{
public function attributes()
{
return ['id', 'name'];
}
public static function index()
{
return 'user/users';
}
}
...
$model = new \common\models\RemoteUser();
$model->find()->where(['id' => 1])->one();
для чего базовый ActiveController
расширил методом search
public $serializer = [
'class' => 'yii\rest\Serializer',
'collectionEnvelope' => 'items',
];
/**
* @return ActiveDataProvider
* @throws \yii\web\HttpException
*/
public function actionSearch()
{
if (!empty($_GET)) {
/** @var ActiveRecord $model */
$model = new $this->modelClass;
foreach ($_GET as $key => $value) {
if (!$model->hasAttribute($key)) {
throw new \yii\web\HttpException(404, 'Invalid attribute:' . $key);
}
}
try {
$provider = new ActiveDataProvider([
'query' => $model->find()->where($_GET),
'pagination' => false
]);
} catch (Exception $ex) {
throw new \yii\web\HttpException(500, 'Internal server error');
}
if ($provider->getCount() <= 0) {
throw new \yii\web\HttpException(404, 'No entries found with this query string');
}
else {
return $provider;
}
}
else {
throw new \yii\web\HttpException(400, 'There are no query string');
}
}
urlRules такие использовал:
[
'class' => 'yii\rest\UrlRule',
'controller' => ['user/users'=>'user/rest'],
'extraPatterns' => [
'GET search' => 'search'
],
],
[
'class' => 'yii\rest\UrlRule',
'controller' => ['user/users'=>'user/rest'],
'tokens' => [
'{id}' => '<id:\\w+>'
]
],
Не скажу, что получилось) Пока что понял, что нужно переопределять (возможно, уже изменяете) методы Сonnection
, точно в Command
прописать формат URL и в самой модели определить к какому activeController
она относится