Database 分页和数据库错误cakephp
可能重复:Database 分页和数据库错误cakephp,database,cakephp,Database,Cakephp,可能重复: 我有一个页面可以工作,但后来决定添加分页功能-它在该页面上工作,现在试图将其复制到另一个页面,我现在收到pdo数据库错误。表示变量Relationship.sender\u id不存在 我有一个关系表,其中包含-id、发送者id、接收者id、到期日期、有效期 下面是函数中的代码 public function index_admin(){ //retrieve Account Id of current User $accountid=$th
我有一个页面可以工作,但后来决定添加分页功能-它在该页面上工作,现在试图将其复制到另一个页面,我现在收到pdo数据库错误。表示变量
Relationship.sender\u id
不存在
我有一个关系
表,其中包含-id、发送者id、接收者id、到期日期、有效期
下面是函数中的代码
public function index_admin(){
//retrieve Account Id of current User
$accountid=$this->Auth->user('account_id');
//Conditions
$conditions=array(
"OR"=> array(
'Relationship.sender_id' => $accountid,
'Relationship.receiver_id' => $accountid)
);
//Find all Relationships where receiver_id = accountid
$relationships=$this->Relationship->find('all', array(
'conditions' => $conditions));
$compName = $this->Account->field('account_name', array('id' => 'Relationship.id'));
$this->paginate = array(
'limit' => 10,
'conditions'=> $conditions);
$this->set('accountid', $accountid);
$this->set('relationship', $this->paginate());
$this->set('compName', $compName);
}
这真的让我抓狂,任何帮助都将不胜感激
这是代码创建的sql查询
SELECT `Relationship`.`id`, `Relationship`.`sender_id`, `Relationship`.`receiver_id`,
`Relationship`.`active`, `Relationship`.`requested`, `Relationship`.`expiry_date`,
`ReceiverAccount`.`id`, `ReceiverAccount`.`street`, `ReceiverAccount`.`city`,
`ReceiverAccount`.`postcode`, `ReceiverAccount`.`state`, `ReceiverAccount`.`country`,
`ReceiverAccount`.`active`, `ReceiverAccount`.`account_name`, `ReceiverAccount`.`abn`,
`SenderAccount`.`id`, `SenderAccount`.`street`, `SenderAccount`.`city`,
`SenderAccount`.`postcode`, `SenderAccount`.`state`, `SenderAccount`.`country`,
`SenderAccount`.`active`, `SenderAccount`.`account_name`, `SenderAccount`.`abn`
FROM
`pra`.`relationships` AS `Relationship` LEFT JOIN
`pra`.`accounts` AS `ReceiverAccount` ON (
`Relationship`.`receiver_id` = `ReceiverAccount`.`id`) LEFT JOIN
`pra`.`accounts` AS `SenderAccount` ON (
`Relationship`.`sender_id` = `SenderAccount`.`id`) WHERE (
(`Relationship`.`sender_id` = 2) OR (`Relationship`.`receiver_id` = 2))
在注释掉分页后调试$relationships时,会得到以下输出
array(
(int) 0 => array(
'Relationship' => array(
'id' => '5',
'sender_id' => '3',
'receiver_id' => '2',
'active' => false,
'requested' => false,
'expiry_date' => '2012-05-09'
),
'ReceiverAccount' => array(
'id' => '2',
'street' => '50 Simmington Circuit',
'city' => 'Greenvale',
'postcode' => '3059',
'state' => 'VIC',
'country' => 'Australia',
'active' => true,
'account_name' => 'Kialla Transport (Operations) Pty Ltd',
'abn' => '2147483647'
),
'SenderAccount' => array(
'id' => '3',
'street' => '31 Simmington Circuit',
'city' => 'Greenvale',
'postcode' => '3059',
'state' => 'VIC',
'country' => 'Australia',
'active' => true,
'account_name' => 'MGD Kialla Pty Ltd',
'abn' => '2147483647'
)
),
删除行:
$this->paginate = array(
'limit' => 10,
'conditions'=> $conditions);
在关系控制器的顶部添加变量:
public $paginate = array(
'Relationship' = > array(
'limit' => 10)
)
);
然后尝试:
$this->set('relationship', $this->paginate('Relationship', $conditions));
这将解决问题…删除行:
$this->paginate = array(
'limit' => 10,
'conditions'=> $conditions);
在关系控制器的顶部添加变量:
public $paginate = array(
'Relationship' = > array(
'limit' => 10)
)
);
然后尝试:
$this->set('relationship', $this->paginate('Relationship', $conditions));
这应该可以解决问题…运气不好,仍然会抛出错误如果你简化了条件,它是否有效。。。比如
$conditions=array('Relationship.sender\u id'=>$accountid)代码>?否,当我将其简化时也会出现相同的错误发件人id或关系id我用debug printoutsee更新了答案更新了问题并让我知道它是否有效没有运气,仍然抛出错误如果你简化了条件是否有效。。。比如$conditions=array('Relationship.sender\u id'=>$accountid)代码>?否,当我将其简化时也会出现相同的错误发件人id或关系id我用debug printoutsee更新了问题的答案并告诉我它是否有效返回debug($relationships)?(注释分页片刻并查看)这是组分配的一部分,可能是重复的,返回debug($relationships)?(注释分页片刻并查看)这是小组作业的一部分,可能是重复的