Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/245.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
Php 将2个模型分成1组结果_Php_Mysql_Database_Cakephp - Fatal编程技术网

Php 将2个模型分成1组结果

Php 将2个模型分成1组结果,php,mysql,database,cakephp,Php,Mysql,Database,Cakephp,感觉我什么都试过了。我正在从两个数据表“Spec”和“Update”构建一个新闻提要。下面是CakePHP代码 // Setup pagination $this->paginate = array( 'Spec' => array( 'fields' => array( 'Spec.id', 'Spec.name' ), 'limit' => 10,

感觉我什么都试过了。我正在从两个数据表“Spec”和“Update”构建一个新闻提要。下面是CakePHP代码

// Setup pagination
$this->paginate = array(
    'Spec' => array(
        'fields' => array(
            'Spec.id',
            'Spec.name'
        ),
        'limit' => 10,
        'conditions' => array(
            'Spec.car_id' => $id
        ),
        'order' => array(
            'Spec.created' => $orderSetting
        )
    ),
    'Update' => array(
        'fields' => array(
            'Update.id',
            'Update.name'
        ),
        'limit' => 10,
        'conditions' => array(
            'Update.car_id' => $id
        ),
        'order' => array(
            'Update.created' => $orderSetting
        )
    )
);
$updates = $this->paginate(array('Spec', 'Update'));
这将返回一个SQL错误

SQL Error: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Update' at line 1
问题是这一行-它只允许一个项目? $updates=$this->paginate(数组('Spec','Update'); 如。 $updates=$this->paginate('Spec')

当然,这不是我想要的

非常感谢您的帮助或指导。

paginate()函数不允许将多个模型作为参数,因为它实际上只是
find()
函数()的代理。您的第二个参数(
'Update'
)将被视为
find()
调用的条件-这将导致SQL错误

SQL Error: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Update' at line 1
您需要在一个模型上创建一个
find()
调用,该调用将返回所需的所有数据。您可以使用模型关系和ContaineableBehavior包含来自其他模型的数据

另一种方法是两种不同的
find()
操作和手动组合结果。但是,您还必须手动处理分页