开发者

Paginating and retriving data with CakePHP

开发者 https://www.devze.com 2023-02-10 21:51 出处:网络
Hi I\'m trying toto do pagination from the KindsController but with data from the LinkModel Tables : Kindslinks

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

精彩评论

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