Request parameters are null in the controller action Yii2

Hello;

I’ve been trying to send data via ajax using get method when I am in the controller action and try to dump the value of the parameters that are in the request they are all null. I don’t know what is wrong in my codes; Here down are them.

1.AJAX


    $.get("http://localhost/kika/web/index.php?r=bien%2Ftuer&idplay=26&idcat=4");

2.Controller:


 public function actionTuer($idplay,$idcat){

              if(User::creator(Yii::$app->request->get('idcat'))){

                  var_dump(Yii::$app->request->get($idplay));//Printing null

                  var_dump(Yii::$app->request->get($idcat));//Printing null

                $model = Play::findOne(Yii::$app->request->get($idplay));

                if($model===null){

                    echo json_encode(array('erreur'=>'Not Found'));

                    Yii::$app->end();

                }else{

                    if($model->delete()){

                        echo json_encode(array('reussite'=>'OK'));

                        Yii::$app->end();

                    }

                }

              }       

              echo json_encode(array('erreur'=>''));

              Yii::$app->end();

        }



What is happening when you type the url in the browser? Can you then read the values? If yes, then your problem is in AJAX call.

Try this:





	$.ajax(

		{

			url: '<?php echo Url::to(['site/loadpostsbyajax'], true); ?>',//This will not work if your function is in JS file. Put your JS code in view file

			dataType:'html',//put JSON if you are returning json

			beforeSend:function (xhr){

				//This function is called before AJAX request. You can use it to show loaders for example

			},

			data:'idplay=26&idcat=4',//Data you are sending

			type: 'GET',//GET method

			success: function(result){

				//Function that is executed on successful ajax call

			},

			error: function(){

				//Function that is executed on error

			}

		}

	);