我有一个SQL查询,可以从不同的表中获取结果。我得到的结果如下:
\app\View\Followings\index.ctp (line 14)
array(
'Following' => array(
'id' => '1',
'user_id' => '3',
'follower_id' => '2'
),
'Blogging' => array(
(int) 0 => array(
'id' => '1',
'value' => 'What is zyzz about ?',
'user_id' => '3',
'created' => '2014-01-01 00:00:00'
)
),
'Photo' => array(
(int) 0 => array(
'id' => '3',
'value' => 'zyzz.jpg',
'user_id' => '3',
'created' => '2014-02-12 00:00:00'
),
(int) 1 => array(
'id' => '2',
'value' => 'zyzz2.jpg',
'user_id' => '3',
'created' => '2015-05-07 00:00:00'
)
)
)
\app\View\Followings\index.ctp (line 14)
array(
'Following' => array(
'id' => '2',
'user_id' => '4',
'follower_id' => '2'
),
'Blogging' => array(
(int) 0 => array(
'id' => '3',
'value' => 'lolpl',
'user_id' => '4',
'created' => '2013-12-01 00:00:00'
),
(int) 1 => array(
'id' => '2',
'value' => 'Do you even lift brah ?',
'user_id' => '4',
'created' => '2015-06-18 00:00:00'
)
),
'Photo' => array()
)
我的问题是如何进入一个单独的数组,其中“Users”混合,“value”按id(或按日期)排序?谢谢。
控制器:
public function index(){
$followings = $this->Following->find('all', array(
'conditions' => array('Following.follower_id' => $this->Auth->user('id')),
'recursive' => 1,
));
$this->set('followings', $followings);
}
答案 0 :(得分:0)
我建议首先尝试使用CakePHP的find()方法的内置选项来获得所需的结果。我不明白你的意思是将用户的结果“混合”,但在你的发现中使用'order'和'group'可能会有所帮助。
对于CakePHP 2.x: http://book.cakephp.org/2.0/en/models/retrieving-your-data.html
如果仍然无法按照您想要的方式获得结果,则可以通过迭代控制器内的$ followings结果来构建新数组,然后使用新数组执行$this->set
跟随$。跟随。