CakePHP deep sorting
I would like sortking by name in assosciate model using Set::sort()
.
My code look like:
$arr = array(
0 => array(
'Category' => array(
'name' => 'aaa'),
'Section' => array(
0 => array(
'name' => '开发者_运维问答b'),
1 => array(
'name' => 'a'),
2 => array(
'name' => 'c'))));
$brr = Set::sort($arr, '{n}.Section.name', 'ASC');
pr($brr);
You were pretty much almost there, you forgot the numeric index for the Section
array.
$arr = array(
0 => array(
'Category' => array(
'name' => 'aaa'),
'Section' => array(
0 => array(
'name' => 'b'),
1 => array(
'name' => 'a'),
2 => array(
'name' => 'c')
)
)
);
$brr = Set::sort($arr, '{n}.Section.{n}.name', 'ASC');
pr($brr);
精彩评论