3

i am using cakephp 3.1. in that i need to use concat the firstname and lastname with space using list of find method..

I tried below code it return with semi columns but i need space instead of semi columns.

Code:

 $query = $articles->find('list', [
        'keyField' => 'id',
        'valueField' => ['firstname','lastname']
    ]);
    $data = $query->toArray(); 

I got below result :

 $data = [
        1 => 'rahul;patel',
        2 => 'raj;patel',
    ];

But i need space instead of semi column (;).

Please guys help me.

Thanks in advance.

Kamlesh Gupta
  • 505
  • 3
  • 17

1 Answers1

0

Currently in the documentation for 3.0 I don't see the support to add parameters in the find function, but I'm not very familiar with cakephp http://book.cakephp.org/3.0/en/orm/query-builder.html

I would try something along these lines. I've commented out an alternative possible return in the array_map. I hope this helps.

  $query = $articles
    ->find()
    ->select(['id','firstname', 'lastname'])
    ->order(['created' => 'DESC']);

  $data = array_reduce($query, function($carry, $item) {
    $carry[$item->id] = $item->firstname.' '.$item->lastname;
    return $carry;
  }, []);
Perspective
  • 642
  • 5
  • 12