在 find('list') 中使用多个 valueField [英] Using multiple valueFields in find('list')

查看:16
本文介绍了在 find('list') 中使用多个 valueField的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在我的 find 方法中使用多个字段 -

Trying to use multiple fields in my find method -

$users = $this->AdressesUsers->users->find('list', [
            'keyField' => 'id',
            'valueField' => ['firstname','lastname'],            
        ]);

工作,有点.因为两者用分号隔开.也尝试使用 mutator 方法,但是失败了.

Works, kinda. Because the two get seperated by a semicolon. Also tried using a mutator method, but this failed badly.

在我的功能中

'valueField' => function ($e) {
        return $e->author->get('full_name');
    }

在我的实体用户中

protected function _getFullName()
    {
        return $this->firstname . '  ' . $this->lastname;
    }

推荐答案

我永远不会弄乱实体,保持它没有逻辑并尽可能简单.

I would never mess with the entity, keep it without logic and as simple as possible.

这里更好的方法是使用您已经尝试过的方法:

A better approach here is to use what you already tried:

'valueField' => function ($e) {
    return $e->first_name . ' ' . $e->last_name . ' ' . $e->more;
}

等只需在此处 debug() 实体,您将看到它包含整个数据集,您可以随意将其组合在一起.

etc Just debug() the entity here and you will see that it contains the whole data set and you can put it together however you like.

这篇关于在 find('list') 中使用多个 valueField的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆