Possible Duplicate:
CakePHP website crashing after pagination
I had a page that worked but then decided to add in the functionality of pagination – it worked on that page and now trying to copy it over to another page I am now getting pdo database errors. saying that the variable Relationship.sender_id doesn’t exist.
I have a relationship table which contains – id, sender_id, receiver_id, expiry_date,active
here is the code in the function
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);
}
this has really thrown me, any help would be appreciated.
this is the sql query the code creates
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))
when I debug $relationships after commenting out the pagination, I get the following output
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'
)
),
remove lines:
at the top of the Relationship controller add variable:
then try:
this hould solve the problem…