Прописываем rules в UrlManager
Код: Выделить всё
// REST for routes
[ 'class' => 'yii\rest\UrlRule', 'controller' => 'routesapi' ],
Код: Выделить всё
[
'pattern' => 'PUT,PATCH routesapi/update/<id:\d+>',
'route' => 'routesapi/update'
],
Код: Выделить всё
'request' => [
'baseUrl' => '/admin',
'csrfParam' => '_csrf-backend',
'cookieValidationKey' => getenv('COOKIE_VALIDATION_KEY'),
'parsers' => [
'application/json' => 'yii\web\JsonParser',
]
],
Контроллер стандартный REST
Код: Выделить всё
'update' => [
'class' => 'yii\rest\UpdateAction',
'modelClass' => $this->modelClass,
'checkAccess' => [$this, 'checkAccess'],
'scenario' => $this->updateScenario,
],
Код: Выделить всё
public function actionUpdate($id) {
$model = Points::find()->where(['id'=>$id])->one();
$model->load(\Yii::$app->getRequest()->getBodyParams(), '');
if ($model->save() === false && !$model->hasErrors()) {
throw new ServerErrorHttpException('Failed to update the object for unknown reason.');
}
return \Yii::$app->getRequest()->getBodyParams();
}
Код: Выделить всё
$actions = parent::actions();
unset($actions['update']);
Код: Выделить всё
axios.put(this.appUrl + '/routesapi/update/', point)
Получаю ошибку
Код: Выделить всё
code:0
message:"Отсутствуют обязательные параметры: id"
name:"Bad Request"
status:400
type:"yii\web\BadRequestHttpException"
Код: Выделить всё
axios
.put(this.appUrl + '/routesapi/update/'+point.id, point)
UPD Пока писала, что в URL забыла из инструкции вот такой параметр.
Код: Выделить всё
'enableStrictParsing' => true,
В чем может быть дело - где я накосячила? Куда копать?