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

Hi developers :)

I have a problem :). I want send values like this


var form = $(this);

            

$.ajax({

url    : form.attr('action'),

type   : 'post',

data   : form.serialize()...



and read like this


$post = Yii::$app->request->post();

$value = $post('value')




but in $post(‘value’) I have ‘undefined’.

ajax send value like FormName[value] = 10 why when I want read $post(‘value’) I don’t have my value. I check $post(‘FormName[value]’) but a have some error from yii2.

How send in ajax value like ‘value’ = 10 not like FormName[value] = 10

I don’t want do


$model = new Model(); 

if ($model->load(Yii::$app->request->post())) {


$value = $model->value;




Thx for help

What was the error?

Are you familiar with the doc?

http://www.yiiframework.com/doc-2.0/yii-web-request.html#post()-detail

The problem is with your javascript . The form sending undefined as value to the server

Please make sure it send right data. as well understand the request handling in Yii2 from here…

http://www.yiiframework.com/doc-2.0/yii-web-request.html

Check this


$value = Yii::$app->request->post("ModelName")["value"];

From debugg a have

When I do

$value = $post(‘Prompter’)[‘kod’];

$value = $post('Prompter[‘kod’]);

I have the same error:


PHP Fatal Error 'yii\base\ErrorException' with message 'Function name must be a string' 


in C:\xampp\htdocs\yii2\frontend\controllers\PrompterController.php:159


Stack trace:

#0 [internal function]: yii\base\ErrorHandler->handleFatalError()

#1 {main}

$value = $post[‘my_value’]; work but it is extra value not from ModelForm (Prompter from)

Oh ,

$post is a array which will contain your post method’s data

so you have to




$post['Prompter']['kod']



Thx ஆரோக்கிய ஜான்சன் :)