CakePHP,可容纳,分组依据
我有一个场景,我尝试在与我的主模型关联的模型上使用可包含的分组。
这是我的输出:
Array
(
[Subfirm] => Array
(
[id] => 1
[firm_id] => 1
[name] => Word Spam Management Fund
[description] => There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.
[active] => yes
[created] => 2011-07-14 18:05:01
[modified] => 2011-07-14 18:05:01
)
[Firm] => Array
(
[id] => 1
[name] => Word Spam
[description] => Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean dictum neque a arcu ultricies semper. Curabitur lacinia, nisi ac cursus mattis, diam ipsum egestas eros, id pharetra dui quam vel sapien. Fusce tempus mauris eu ligula rutrum rutrum. Cras sit amet metus nisl. Nam feugiat malesuada justo, lacinia mollis nulla iaculis sed. Sed dui sapien, aliquam vel vestibulum eget, suscipit ac dui. Donec et neque dapibus lorem euismod convallis. Sed nec mauris vel velit venenatis fermentum et non velit. Pellentesque tincidunt, nisi vitae sollicitudin malesuada, lectus orci egestas neque, vitae placerat magna nisi eu nulla. Donec eleifend laoreet ligula vitae faucibus. Donec eget felis eros. Nullam ligula nisl, porttitor at viverra a, auctor ullamcorper orci. Fusce vestibulum turpis mollis velit tristique luctus.
[website] => http://www.wordspam.com
[active] => yes
[created] => 2011-07-11 11:33:46
[firmtype_id] => 1
[aum] => 600.77
[modified] => 2011-07-10 22:55:16
[Firmtype] => Array
(
[id] => 1
[name] => Hedge Fund
[active] => yes
[created] => 2011-07-12 12:30:42
[modified] => 2011-07-12 12:30:42
)
)
[Subfirmdetail] => Array
(
[0] => Array
(
[id] => 1
[subfirm_id] => 1
[subfirmdetailtype_id] => 1
[value] => 400
[date] => 2011-07-14
[created] => 2011-07-14 19:09:42
[modified] => 2011-07-14 19:09:42
[active] => yes
[Subfirmdetailtype] => Array
(
[id] => 1
[firmtype_id] => 1
[name] => AUM
[datatype_id] => 1
[created] => 2011-07-14 18:09:23
[modified] => 2011-07-14 18:09:23
[active] => yes
[Datatype] => Array
(
[id] => 1
[name] => DOUBLE
[created] => 2011-07-14 18:14:58
[modified] => 2011-07-14 18:14:58
[active] => yes
)
)
)
[1] => Array
(
[id] => 2
[subfirm_id] => 1
[subfirmdetailtype_id] => 2
[value] => 2.34
[date] => 2011-07-14
[created] => 2011-07-14 19:09:42
[modified] => 2011-07-14 19:09:42
[active] => yes
[Subfirmdetailtype] => Array
(
[id] => 2
[firmtype_id] => 1
[name] => Standard Deviation
[datatype_id] => 1
[created] => 2011-07-14 18:09:23
[modified] => 2011-07-14 18:09:23
[active] => yes
[Datatype] => Array
(
[id] => 1
[name] => DOUBLE
[created] => 2011-07-14 18:14:58
[modified] => 2011-07-14 18:14:58
[active] => yes
)
)
)
[2] => Array
(
[id] => 3
[subfirm_id] => 1
[subfirmdetailtype_id] => 1
[value] => 370
[date] => 2011-07-11
[created] => 2011-07-11 12:00:00
[modified] => 2011-07-11 12:00:00
[active] => yes
[Subfirmdetailtype] => Array
(
[id] => 1
[firmtype_id] => 1
[name] => AUM
[datatype_id] => 1
[created] => 2011-07-14 18:09:23
[modified] => 2011-07-14 18:09:23
[active] => yes
[Datatype] => Array
(
[id] => 1
[name] => DOUBLE
[created] => 2011-07-14 18:14:58
[modified] => 2011-07-14 18:14:58
[active] => yes
)
)
)
)
)
我想按 SubFirmDetail 进行分组,并且仅根据 subFirmDetailType 显示最新的 SubFirmDetail。这是我当前在控制器中使用的代码:
function view($id = null) {
$this->Subfirm->recursive = -1;
$data = $this->Subfirm->find('first', array(
'contain' => array(
'Subfirmdetail' => array(
'Subfirmdetailtype' => array(
'Datatype',
),
),
'Firm' => array(
'Firmtype',
),
),
'conditions' => array('Subfirm.id' => $id),
));
$this->set('subfirm', $data);
if (!$id) {
$this->Session->setFlash(__('Invalid subfirm', true));
$this->redirect(array('action' => 'index'));
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我最终不得不在数据库中创建一个视图并输出一个数组,该数组包含在我的条件子句中......对于那些尝试相同的人。
I ended up having to create a view in the database and output an array which I included in my conditions clause... For those attempting the same.
试试这个:
或者查看这个链接:
Try this:
Or see this links: