开发者

Paginating and retriving data with CakePHP

Hi I'm trying to to do pagination from the KindsController but with data from the LinkModel

Tables :

  Kinds       links          
     id           id
     name         title
     order        url
                  kind_id
                  order

model:

class Kind extends AppModel{

        var $name = 'Kind';
        var $hasMany = 'Link';
    }

controller:

class KindsController extends AppController{

    var $name = 'Kinds';
    var $paginate = array(

        'Kind'=> array(
            'limit' => 12,
            'order'=> array('Kind.order'=>'ASC')

        )

    );

}

desired result (view) ;

 Kind.name ( numbers of links )
开发者_StackOverflow社区    links.name
    ........
    ..........

    Kind.name ( numbers of links )
    links.name
    ........
    ..........

i'm using the kinds.order and links.order to control how the data is displayed in the view from an admin area.

i need to retrive data from the kinds table ordered by kinds.order ASC and the number of links, and the links data ordered by links.order

thanks


You can define order in the relation like this:

class Kind extends AppModel{
    var $hasMany = array(
        'Link' => array(
            'className' => 'Link',
            'order' => 'Link.name'
        ),
    );
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜