开发者

sort on array read

开发者 https://www.devze.com 2023-03-04 23:56 出处:网络
In my controller I have 开发者_运维问答 var $uses = array(\'User\',\'Customer\'); then I am using read to call the users

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

精彩评论

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