小编kos*_*dpo的帖子

doctrine 2查询构建器和连接表

我想在我的主页上为每个帖子收到所有评论

return 
$this->createQueryBuilder('c')
->select('c')
->from('Sdz\BlogBundle\Entity\Commentaire' ,'c')                
->leftJoin('a.comments' ,'c')->getQuery()->getResult() ;
Run Code Online (Sandbox Code Playgroud)

但是我收到了这个错误

[Semantical Error] line 0, col 58 near '.comments c,': Error:
Identification Variable a used in join path expression but was not defined before.
Run Code Online (Sandbox Code Playgroud)

PS:映射是正确的,因为我可以看到页面文章及其注释.

left-join query-builder doctrine-orm

19
推荐指数
1
解决办法
6万
查看次数

symfony2通过用户名或电子邮件登录

我正在使用Symfony2的标准身份验证机制,我想让用户使用他的用户名或电子邮件登录,但我不知道为什么它不起作用.我已经测试了存储库类,它按预期工作.我遵循了这个方法.

这是我的用户提供者类:

<?php

namespace My\UserBundle\Entity;

use Doctrine\ORM\EntityRepository ,
Symfony\Component\Security\Core\User\UserProviderInterface ,
Symfony\Component\Security\Core\User\UserInterface;

/**
* UserRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class UserRepository extends EntityRepository implements UserProviderInterface 
{
    function loadUserByUsername($username)
    {

        $qb = $this->createQueryBuilder('u') ;
        return 
        $qb->select('u')
        ->where(
            $qb->expr()->orx(
                $qb->expr()->like('u.username' ,':username') ,
                $qb->expr()->like('u.email' ,':username')
            )
        )
        //->andWhere($qb->expr()->eq('u.enabled' ,'true') )
        ->setParameters(array('username' =>$username ) )        
        ->getQuery()
        ->getResult() ;                  
    }

    function refreshUser(UserInterface $user)
    {
        return $this->loadUserByUsername($user->getUsername() );
    }

    function …
Run Code Online (Sandbox Code Playgroud)

email authentication username symfony

5
推荐指数
2
解决办法
6657
查看次数