$_GET param with ajax

I was just refactoring some code and broke something,everything worked fine before. I had a modal on a page that did some ajax requests to get possible addresses for a select2 (kartik) box. When I refactored I just moved all the ajax methods to their own controller and updating the url links for the ajax request.

But I’m finding now that my $_GET params don’t seem to be mapped and I can’t seem to fix it.

example:




// url: ajax-extraction/ajax-address-list?q=50

public function actionAjaxAddressList($q = null, $id = null)

    {

        // line below if uncommented works returns json array {"q": "50"}

        /*$q = Yii::$app->request->get('q'); return json_encode( $q ); */ 

        // line below returns null as if the $_GET param hasn't been mapped to variable in

        // function definition $q

        return json_encode( $q );




I have also tried adding this specific route to the url manager, but the problem still persists?

Hi Jonny,

can you try to use [color=#4A4A4A][font=Helvetica, Arial, sans-serif][size=2]extract($_GET[/size][/font][/color][color=#4A4A4A][font=Helvetica, Arial, sans-serif][size=2]) and check are you able to fix your problem[/size][/font][/color]

Both $_GET[‘q’] and Yii::$app->request->get(‘q’) work as mentioned above. But $q should exist from the controller declaration. I shouldn’t have to call Yii::$app->request->get(‘q’) ???