4

I have url like this

 http://localhost/belajar4/web/index.php?r=data%2Fsingle&id=2&DataSearch[TANGGAL]=2015-08-04&DataSearch[TANGGAL_SELESAI]=2015-08-12 

And I want to get DataSearch['Tanggal'] dan DataSearch[TANGGAL_SELESAI]

I have tried for id with

 Yii::$app->request->queryParams['id'] 

And it was success for it, but not with DataSearch['Tanggal']

When I try for DataSearch['Tanggal'] the error is

 Undefined index: DataSearch[TANGGAL] 

I think it should have easy to answer but i am newbie for yii2 and i didnt find the solution yet

Danila Ganchar
  • 7,271
  • 11
  • 35
  • 59

3 Answers3

6

You can get them from array like this:

Yii::$app->request->queryParams['DataSearch']["TANGGAL_SELESAI"]
Yii::$app->request->queryParams['DataSearch']["TANGGAL"]
Jakuje
  • 20,643
  • 11
  • 53
  • 62
2

You can also use combination of ArrayHelper::getValue() and Yii::$app->request->get() with dot notation:

use Yii;
use yii\helpers\ArrayHelper;


...

$value = ArrayHelper::getValue(Yii::$app->request->get(), 'DataSearch.TANGGAL_SELESAI');

The main advandage is you can avoid Undefined index exception and change default value (third parameter).

Official docs:

arogachev
  • 31,868
  • 6
  • 105
  • 113
-1

I had faced slimier issue & spent lots of time to get the value but somehow I found solution like below.

// Trying to print the value

echo Yii::$app->request->queryParams['DataSearch']['"TANGGAL_SELESAI"'];

echo Yii::$app->request->queryParams['DataSearch']['"TANGGAL"'];
Priy Ranjan
  • 109
  • 1
  • 8