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