在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);
});
在您的控制器中,您是否可以检测到url和/或检查数据是否未提交,并对'Request'对象执行数据解码? – 2011-12-21 06:18:39
@JaredFarrish如果一切都失败了,我可能会这样做,但如果可以的话,我想保留解析出控制器。 – benzado 2011-12-22 06:06:46