0
votes

In CakePHP 3 I can access a POST variable such as start like this:

$this->request->getData('start')

If my POST value is in the form of an array - in plain PHP such as $_POST['order'][3]['column'] I can access it in Cake like this:

$this->request['data']['order'][3]['column']

Is this the correct (or only) way to do this, or should you also be able to use getData() to access it?

1
Use the OO way to access things. There are reasons why the interfaces exists to access data through them. See api.cakephp.org/3.4/class-Cake.Http.ServerRequest.html#_getData - floriank
Ok, but how could I access something that's in an array format as per my example (['order'][3]['column'])? I get how you do it for simple items where you just pass the name as a string to getData but that doesn't work for arrays, or so it seems? - Andy
As the API doc tells you Allows you to use Hash::get() compatible paths. so check api.cakephp.org/3.4/class-Cake.Utility.Hash.html#_get - floriank

1 Answers

3
votes

Use the OO way to access things. There are reasons why the interfaces exists to access data through them. See getData().

// As array
$this->request->getData('order')[3]['column'];

// https://api.cakephp.org/3.4/class-Cake.Utility.Hash.html#_get
$this->request->getData('order.3.column');