I’m having a strange thing in cakephp. So I try to explain it first.
I’m having:
- two tables (staff and staffgroups)
- a groupleader per group which is a staff
- a virtual field, which CONCATs first and last name
- the whish to order the list by lastname
Staff/model
public $virtualFields = array(
[...] ,
'fullnameForList' => 'CONCAT(Staff.lastname, ", ", Staff.firstname)',
[...]
function in Staffgroup/controller
public function getGroupLeaderListArray(){
$this->loadModel('Staff');
$loc_list = $this->Staff->find("list",
array("fields" => array("id", 'fullnameForList')),
array("order" => array("Staff.lastname ASC" ))
);
$this->set('GroupLeaderList',$loc_list);
}
outputs of the list
-
When I’m having the function getGroupLeaderListArray as it is above, i get the content of the virtualfield fullnameForList, but its not in order. eg. Lastname, Firstname
-
When I’m putting the array order before fields, it is shown in order but the wrong field. eg. Firstname Lastname
how do I get the list with the virtual field and correct order. I don’t know further and I’m gaining weight and loosing hairs because of this problem. help apreciated big time!
cheers endo
You are using invalid array structures here. you need to pay attention on how arrays are working in cake. One array with named keys (you have multiple arrays here) as second param for find(), for example.
So its: