L
L
Lander2016-11-03 14:12:09
Yii
Lander, 2016-11-03 14:12:09

Why is there a redirect in Yii2 when creating an entity via REST?

The action for rest to create an entity has the following code:

namespace yii\rest;
...
class CreateAction extends Action
{ 
...
    public function run()
    {
        ...
        if ($model->save()) {
            ...
            $response->getHeaders()->set('Location', Url::toRoute([$this->viewAction, 'id' => $id], true));
        } elseif (!$model->hasErrors()) {
...

Question: Why is there $response->getHeaders()->... for the rest of the request? As a result, I am thrown to the actionView, which is not implemented (well, I don’t need it in the condition of this task). And if implemented, then the model will not have a script installed and, accordingly, the fields () method will not return anything.
Maybe I'm doing something wrong?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question