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

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

问题描述

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

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

因为两个分号分开。



在我的功能

 'valueField'=>函数($ e){
return $ e-> author-> get('full_name');



$ b $ p
$ b $ p $在我的实体用户中

  protected function _getFullName()
{
return $ this-> firstname。 ''。 $这 - >姓;


解决方案

实体,保持它没有逻辑,并尽可能简单。



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

 'valueField'=>函数($ e){
返回$ e-> first_name。 ''。 $ e-> last_name。 ''。 $ E->更多;






只要在这里debug()实体,你会看到它包含整个数据集,你可以把它放在一起,不过你喜欢。


Trying to use multiple fields in my find method -

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

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

In my Function

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

In my Entity User

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;
}

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天全站免登陆