Php 将2个模型分成1组结果
感觉我什么都试过了。我正在从两个数据表“Spec”和“Update”构建一个新闻提要。下面是CakePHP代码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,
// 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()
操作和手动组合结果。但是,您还必须手动处理分页