Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 原则DQL-选择作为新记录添加的列别名_Php_Symfony_Doctrine_Dql - Fatal编程技术网

Php 原则DQL-选择作为新记录添加的列别名

Php 原则DQL-选择作为新记录添加的列别名,php,symfony,doctrine,dql,Php,Symfony,Doctrine,Dql,我有一个链接到用户配置文件实体的用户实体 我需要能够连接用户的名字和姓氏以进行过滤 我的查询大致如下所示: $qb = $this->createQueryBuilder('users'); $qb ->addSelect('users') ->innerJoin('users.profile', 'profile') ->addSelect('profile') ->addSelect('CONCAT(profile.firstNa

我有一个链接到用户配置文件实体的用户实体

我需要能够连接用户的名字和姓氏以进行过滤

我的查询大致如下所示:

$qb = $this->createQueryBuilder('users');
$qb
    ->addSelect('users')
    ->innerJoin('users.profile', 'profile')
    ->addSelect('profile')
    ->addSelect('CONCAT(profile.firstName, \' \', profile.lastName) AS fullName')
;
我希望全名被视为用户属性或配置文件,但我在结果中将全名作为一个全新的记录:

[0] => Array (
    [id] => 5
    [username] => admin
    [profile] => Array (
        [firstName] => John
        [lastName] => Doe
    )
), 
[fullName] => John Doe
我尝试将该列别名为“users.fullName”,但这给了我一个错误

[语法错误]第0行,第87列:错误:预期的条令\ORM\Query\Lexer::T_FROM,get'.'。

正确的方法是什么


谢谢

为什么不在选择方法中提供所需列的完整列表:

    ->select('user.id, user.username, CONCAT(profile.firstName, \' \', profile.lastName) AS fullName')
你应该收到正确的assoc数组

请记住添加适当的where子句:

    ->where("CONCAT(profile.firstName, ' ', profile.lastName) LIKE :name")
    ->setParameter('name', '%' . $name . '%')

是否要在查询中匹配
全名
,还是在PHP中更高版本?使用然后使用ResultsMapping将字段映射到类属性。lxg:是的,我需要在查询中进行匹配。感谢您的反馈。虽然这确实有效,但理想情况下,我希望保留默认的条令行为并返回实体集合。有什么方法可以做到吗?我建议您返回entites集合没有简单的方法可以将自定义数据库属性映射到实体结果。好的,我想最简单的方法是添加一个带有连接值的where条件,而不是将其作为附加字段加载。谢谢你的帮助。