Cakephp3.xでは下記URLの記事を参考にアクセスできていたのすが、4.xだと空になってしまう。
4.xでは、Json、XMLで入力されたデータにアクセスする場合、オプション機能でそれをデコードが必要でした。
CakePHP + AjaxでのPOSTで受け取った情報が空になる原因
https://blog.supersonico.info/?p=3172
Cakephp 3.x
cakephp3.x&sample.php
//セキュリティコンポーネントを一時無効
if ($this->params['action'] == アクション名) {
$this->Security->csrfCheck = false;
$this->Security->validatePost = false;
}
//getDate()で受け取り
$post_data = $this->request->getData();
Cakephp 4.x
cakephp4.x&sample.php
//セキュリティコンポーネントを一時無効
if ($this->params['action'] == アクション名) {
$this->Security->csrfCheck = false;
$this->Security->validatePost = false;
}
//input()のオプション機能でデコードし受け取り
$post_data = $this->request->input('json_decode');
参考:
リクエストとレスポンスオブジェクト
PUT、PATCH または DELETE データ
https://book.cakephp.org/4/ja/controllers/request-response.html