Fadly Dzil
Fadly Dzil

Reputation: 2206

Get variable GET in Yii2 not working

Basiclly I have an url that have a parameter.

So, I need to access those parameter using GET. This is the GET that coming:

Array
   (
     [r] => hanwa/incoming-pipe/assign-incoming
     [1] => Array
            (
              [min_urut] => 1
              [max_urut] => 44
            )

     [_] => 1496645704980
    )

In docs, docs, We can use like this :

 echo $request->get('min_urut');

But, I got nothing. Please Advise.

Upvotes: 0

Views: 58

Answers (2)

Sersh
Sersh

Reputation: 308

Judging by the fact that you have an array with the key [r] you have an associative array, method get() you will not get it, you need to do it just like this ..

echo $request->get()[1]['min_urut'];

Upvotes: 2

vijay nathji
vijay nathji

Reputation: 1638

Use Concept of ArrayHelper class :-> http://www.yiiframework.com/doc-2.0/guide-helper-array.html#getting-values ex:

$data = ArrayHelper::getValue($request->get(), 'Temp.yourvalue.yourindex');

Main use of $request->get() method mainly returns to you a value from $_GET, so example is

$temp = $request->get('Temp'); // Here $temp variable contains $_GET['Temp']
$data = $temp['yourvaluename'][0];

Upvotes: 2

Related Questions