A
A
Alexander Stepanov2019-03-07 22:13:07
Yii
Alexander Stepanov, 2019-03-07 22:13:07

Why does Yii::$app->request->post() fail?

The action stopped working in the controller.
The logs are clean, no errors are thrown.
If ($form->load(Yii::$app->request->post()) && $form->validate()) doesn't work.
The request has a filled $_POST, but the Request Body is Empty.
In the create action, it returns a page with filled fields...
Action code:

public function actionCreate()
    {
        $form = new ProductCreateForm();
        if ($form->load(Yii::$app->request->post()) && $form->validate()) {
            try {
                $product = $this->service->create($form);
                return $this->redirect(['view', 'id' => $product->id]);
            } catch (\DomainException $e) {
                Yii::$app->errorHandler->logException($e);
                Yii::$app->session->setFlash('error', $e->getMessage());
            }
        }
        return $this->render('create', [
            'model' => $form,
        ]);
    }

What could be the problem and where to dig?
Everything worked, but ... suddenly stopped

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
morricone85, 2019-03-07
@morricone85

$form->load(Yii::$app->request->post()); 

if ($form->validate()) {
 ....
} else {
$errors = $form->errors;
print_r($errors);
}

A
Alexander Stepanov, 2019-03-08
@Exebeche

By a happy coincidence, it turned out that the product did not want to be saved until there was not a single "Product characteristics" object in the system
Damn, I almost turned gray ...
I'll pick the Characteristics so as not to interfere.
Maybe it will be possible to understand why they spoiled life so much.
Many thanks to all who responded and + to karma

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question