Yes, I do it this way in my app:

$this->loadModel('Post');
$this->paginate = array('Post' => array('conditions' => //conditions ), 
'limit' => '8', 'order' => array('Post.created' => 'desc')));
$data = $this->paginate('Post');
    $this->set('posts', $data);


Hope it helped

Le lundi 25 juin 2012 03:14:32 UTC+2, 42startups a écrit :
>
> Ah ok, so how would I paginate and limit results to 10?...
>
> $this->loadModel('Tag', $id);
> $tag = $this->Tag->read();
>
> On Monday, June 25, 2012 6:11:55 AM UTC+10, JonStark wrote:
>>
>> I find it easier to use LoadModel to display and sort posts from HABTM...
>>
>> Le dimanche 24 juin 2012 10:40:04 UTC+2, 42startups a écrit :
>>>
>>> Wow, CakePHP really hasn't got this problem sorted.
>>>
>>> After hours of searching I came across the solution below (which may or 
>>> may not be outdated), but I'm having issues applying paginatior 'limit' => 
>>> 10 or other ordering.
>>>
>>> Any ideas what I'm missing?
>>>
>>> My model:
>>>
>>> public $hasAndBelongsToMany = array(
>>>     'Post' => array(
>>>         'className'              => 'Post',
>>>         'joinTable'              => 'tags_posts',
>>>         'foreignKey'             => 'tag_id',
>>>         'associationForeignKey'  => 'post_id',  
>>>         'order'                  => array('Post.created DESC'),
>>>         'unique'                 => true
>>>     )
>>> );
>>>
>>> In my controller in view()
>>>
>>> public function view($id) {
>>>     $this->Tag->bindModel(array('hasOne' => array('TagsPost')), false);     
>>>     $this->set('tag', $this->paginate('Tag', array('TagsPost.tag_id' => 
>>> $id))); 
>>> }
>>>
>>> In my view I then had to change:
>>>
>>> foreach ($tag['Post'] as $post)
>>>
>>> to
>>>
>>> foreach ($tag[0]['Post'] as $post)
>>>
>>>

-- 
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

Reply via email to