你好我是cakephp的新手我面对查看数据的问题我有一个用户表与其他表的关系,我查看同一页面中的所有数据,但我不知道如何显示其他表数组数据按降序排列,具有相同的查找用户函数。
public function fillprofile($id = null) {
$id = $this->Auth->user('id');
$data = $this->User->find('first', array('conditions' => array('User.' . $this->User->primaryKey => $id)));
$this->set('data', $data);
}
用户表与Userdata表的关系
[User] => Array
(
[id] => 2
[username] =>
[onboarding_user] => 0
[email] => test@gmail.com
[password] => 95e14332b6a34e6c4c5e196c497e855b0ceb95a5
[uni_code] => 7L1H
[fullname] => Alex sharma
[profile_img] => img/profile/1504870214_e211498fca9dd372e0db69f23b31756e.png
[description] => Developer
[updated_date_time] => 2017-09-08 08:21:31
[created_date_time] => 2017-07-06 16:23:27
)
[Userdata] => Array
(
[0] => Array
(
[id] => 13
[user_id] => 2
[position_title] => Developer
[company_name] => TEST 2
[created_date_time] => 2017-08-18 13:19:53
[updated_date_time] => 0000-00-00 00:00:00
)
[1] => Array
(
[id] => 19
[user_id] => 2
[position_title] => Angular Js
[company_name] => TEST
[created_date_time] => 2017-09-08 16:31:48
[updated_date_time] => 0000-00-00 00:00:00
)
)
答案 0 :(得分:0)
将您的fillprofile功能更改为包含订单参数:
public function fillprofile($id = null) {
$id = $this->Auth->user('id');
$data = $this->User->find('first', array('conditions' => array('User.'
. $this->User->primaryKey => $id),
'order'=>'Userdata.position_title DESC'));
$this->set('data', $data);
}
有关find可选参数的更多信息,请参阅: https://book.cakephp.org/2.0/en/models/retrieving-your-data.html