开发者

sort on array read

In my controller I have

开发者_运维问答
var $uses = array('User','Customer');

then I am using read to call the users

$loggedOutCustomer = $this->User->read(null, $this->Auth->user('id'));

this gives me users and cutsomers that I can use but I want to do a sort on customers name. How can i do that in cake?


You can set the default order in your User model.

If Customer belongsTo User, User hasMany Customer.

In your User model, under the hasMany variable, find the Customer record and add Customer.name to the order array key.

Also, please remove the cakephp version tag that you are not using.

You can also add your sorting options when you're using the find() method of your model.

This can also be defined in the pagination array

Another option would be to use the Containable behavior


Give this a try

$loggedOutCustomer = $this->User->find('first', array('conditions' => array('User.id' => $this->Auth->user('id')), 'order' => 'Customer.name ASC'));
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜