我需要对一个表进行分页,我只需要查看分配给我的项目,我该如何实现?
我有的是这个
//My Task Pagination
$this->paginate = array(
'Project' => array(
'limit' => $limit,
'contain' => array('ProjectReminderUser.user_id' => $this->Session->read('Auth.User.id')),
'conditions' => array(
'User.group_id' => $this->Session->read('Auth.User.group_id'),
'Project.project_status_id' => PROJECT_STATUS_OPEN,
),
)
);
$this->set('myTasks', $this->paginate('Project'));
//debug($this->paginate('Project'));
但似乎包含根本不起作用。调试的结果是这样的
array(
(int) 0 => array(
'Project' => array(
'id' => '9',
'project_type_id' => '0',
'contact_id' => '2',
'company_id' => '6',
),
'ProjectReminderUser' => array(
(int) 0 => array(
'id' => '11',
'user_id' => '2',
'project_id' => '9'
)
),
(int) 1 => array(
'Project' => array(
'id' => '1',
'project_type_id' => '0',
'contact_id' => '1',
'company_id' => '3',
),
'ProjectReminderUser' => array(
(int) 0 => array(
'id' => '2',
'user_id' => '1',
'project_id' => '1'
),
(int) 1 => array(
'id' => '1',
'user_id' => '2',
'project_id' => '1'
)
),
)
)
所以我想要实现的是让分页只显示数组索引 1,因为 ProjectReminderUser 有 user_id = 1 (分配给我的项目)
类似的东西。我尝试使用可包含但它不起作用,也许我这样做的方式有问题?