-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug in create action of \yii\rest\ActiveController #16812
Comments
Please look at this line : yii2/framework/rest/CreateAction.php Line 42 in b070b5f
I think it's better we change it to something like this: /**
* Creates a new model.
* @return \yii\db\ActiveRecordInterface the model newly created
* @throws ServerErrorHttpException if there is any error when creating the model
*/
public function run()
{
/* @var $model \yii\db\ActiveRecord */
$model = new $this->modelClass([
'scenario' => $this->scenario,
]);
$model->load(Yii::$app->getRequest()->getBodyParams(), '');
// Change checkAccess method to here.
if ($this->checkAccess) {
call_user_func($this->checkAccess, $this->id, $model);
}
if ($model->save()) {
$response = Yii::$app->getResponse();
$response->setStatusCode(201);
$id = implode(',', array_values($model->getPrimaryKey(true)));
$response->getHeaders()->set('Location', Url::toRoute([$this->viewAction, 'id' => $id], true));
} elseif (!$model->hasErrors()) {
throw new ServerErrorHttpException('Failed to create the object for unknown reason.');
}
return $model;
} |
This was referenced Oct 22, 2018
While it looks like a good change, no enhancements are accepted into 2.0 anymore. You can propose your change there: https://github.com/yiisoft/yii-rest |
Thank you. i will create a new issue in that is create a pull request. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What steps will reproduce the problem?
Consider that you are using
ActiveController
and want to create an entity in your db.When you send post request to create action and want check access of user that requested.
What is the expected result?
You expect that the model object in checkAccess method filled by user input but it's not.
What do you get instead?
The model object is null.
Additional info
The text was updated successfully, but these errors were encountered: