需要在cakephp 3.x中使用查找方法列表的concat


need to use concat with list of find method in cakephp 3.x

我使用的是cakephp 3.1。在这我需要使用concat的名字和姓氏与空间使用查找方法的列表..

我尝试了下面的代码,它返回半列,但我需要空间而不是半列。

:

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

我得到了以下结果:

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

但我需要空格而不是半列(;)。

请大家帮帮我。

目前在3.0的文档中,我没有看到在查找函数中添加参数的支持,但我对cakephp不太熟悉http://book.cakephp.org/3.0/en/orm/query-builder.html

我会尝试一些类似的东西。我已经注释掉了array_map中另一个可能的返回值。我希望这对你有帮助。

  $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;
  }, []);