Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从cakephp中的json数组中删除模型名_Php_Arrays_Json_Cakephp - Fatal编程技术网

从cakephp中的json数组中删除模型名

从cakephp中的json数组中删除模型名,php,arrays,json,cakephp,Php,Arrays,Json,Cakephp,我已经在cakephp控制器中设置了自定义搜索操作 public function search() { $results = []; $results['data'] = $this->Content->find('first', array( 'conditions' => array($this->request->params['pass'][0] . ' like' => "%" . $this->request-&

我已经在cakephp控制器中设置了自定义搜索操作

public function search() {

$results = [];
$results['data'] = $this->Content->find('first', 
    array(
        'conditions' => array($this->request->params['pass'][0] . ' like' => "%" . $this->request->params['pass'][1] . "%")), array('contain' => false)
    );

if(count($results['data'])>0){
    $results['success'] = true;
    $this->set(compact('results'));
    $this->set('_serialize', array('results'));
}
else{
    $results['success'] = false;

}

}
我遇到的问题是,我的API的其余部分将数据格式化如下:

{
"success": true,
"data": [
{
    "id": "5509be6c-9ef8-42c3-af39-2d492773a233",
    "title": "test2",
    },
    {
        "id": "5509be6c-9ef8-42c3-af39-2d492773a233",
        "title": "test1"
    }
    ]
}
但我现在从cakephp获得的搜索操作是:

{
"results": {
    "success": true,
    "data": {
        "Content": {
            "id": "52efcbeb-e984-4a2e-b76f-0cc34056922c",
            "title": "Homeasdfasdf",
        }
    }
}}
如何去掉额外的“results”数组包装器,使数据以相同的格式显示?

使用php函数。在你的控制器里

$results = current($results);
在调用
set()
之前