Andy
Andy

Reputation: 5395

CakePHP 3 - $this->request->getData when reading POST arrays

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?

Upvotes: 0

Views: 5428

Answers (1)

floriank
floriank

Reputation: 25698

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');

Upvotes: 3

Related Questions