在 bootstrap.php 脚本中尝试以下操作。如果请求数据数组中只有一项,并且该项可以解码,则请求数据将替换为解码后的 json 数据。
use \lithium\action\Dispatcher;
Dispatcher::applyFilter('run', function($self, $params, $chain) {
// Only check for JSON data for a certain URL
if($params['request']->url == 'your/url/here') {
// If the data array only has one element and the key can be decoded as
// JSON data, replace the request data with the decoded JSON array
if(count($params['request']->data) == 1) {
$keys = array_keys($params['request']->data);
$data = $keys[0];
if(($data = json_decode($data, true)) != null) {
$params['request']->data = $data;
}
}
}
return $chain->next($self, $params, $chain);
});