Hi,
I have a Topic model, which in turn $hasMany Post. In my TopicsController,
I am doing a find() on the Topic ID to retrieve a single topic and then
using Containable to get all the posts for the topic. I would like to use
the Paginate component to limit the number of posts returned when fetching
the topic but can't figure out how. Everything I've read is about limiting
the number of topics, rather than posts.
My custom find method in my Topic model:
protected function _findOne($state, $query, $results = array())
{
if ($state == 'before')
{
$query['contain'] = array(
'Category',
'Member' => array(
'fields' => array('id', 'name'),
),
'Post' => array(
'Member' => array(
'fields' => array('id', 'name'),
),
'PostContent',
),
);
return $query;
}
return $results;
}
This gives me a resultset in the following format:
array(
0 => array(
'Topic' => array(
...
),
'Category' => array(
...
),
'Member' => array(
...
),
'Post' => array(
0 => array(
'Member' => array(
...
),
'PostContent' => array(
0 => array(
...
)
)
),
1 => array(
...
),
... etc ...
)
)
)
My TopicsController currently has the following (although it has no effect):
public $paginate = array(
'one',
'paramType' => 'querystring',
'Post' => array(
'limit' => 5,
)
);
public function view($id)
{
$topic = $this->paginate(array('Topic.id' => $id));
...
}
So, to clarify, I want to fetch a single topic, but use Paginate to limit
the number of posts that are returned and allow me to use pagination links
in the view.
Thanks in advance,
Alan.
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others
with their CakePHP related questions.
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php