Skip to content

Latest commit

 

History

History
18 lines (16 loc) · 627 Bytes

TableName.md

File metadata and controls

18 lines (16 loc) · 627 Bytes

setPrimaryTable根据参数动态设置表名

  • 主要使用setPrimaryTable方法

      public function getPageQuery(string $yearMonth, string $username = ''): \Doctrine\ORM\Query
      {
          $this->getClassMetadata()->setPrimaryTable([
              'name' => 'login_log_'.$yearMonth
          ]);
          $qb = $this->createQueryBuilder('a');
          $qb->select('a');
          if(!empty($username)){
              $qb->where($qb->expr()->like('l.username', ':user'))
                  ->setParameter('user','%'. $username .'%');
          }
    
          return $qb->orderBy('a.id', 'DESC')
              ->getQuery();
      }