我的学说查询显然在checkmate::assert_numeric(1, names = "named")
#> Error in withCallingHandlers({: Assertion on '1' failed: Vector must be named.
返回了错误的类型,但是我不明白为什么。它说返回数组;这就是我所期望的...
控制器:
getResult()
存储库
public function checkbrute($username, $email ) {
$repository = $this->getDoctrine()->getRepository(LoginAttempts::class);
$now = time();
$valid_attempts = $now - (2 * 60 * 60);
$attempts = $repository->emailLoginAttempts($email, $valid_attempts);
return sizeof($attempts);
}
错误:
public function emailLoginAttempts($email, $valid_attempts): ?LoginAttempts
{
return $this->createQueryBuilder('l')
->select('l.time')
->andWhere('l.email = :val')
->andWhere('l.time > :val2')
->setParameter('val', $email)
->setParameter('val2', $valid_attempts)
->getQuery()
->getResult() //ERROR HERE
;
}
实体:
Return value of App\Repository\LoginAttemptsRepository::emailLoginAttempts() must be an instance of App\Entity\LoginAttempts or null, array returned
答案 0 :(得分:2)
您的emailLoginAttempts
实际上是返回LoginAttempts
的数组,因此,此PHP给您错误。解决方法取决于您的实际逻辑:
LoginAttempts
接收单个emailLoginAttempts
实例-您需要将getResult()
替换为getOneOrNullResult()
。LoginAttempts
实例的数组-您需要更新方法签名以返回数组:public function emailLoginAttempts($email, $valid_attempts): array
并添加PHPDoc @return LoginAttempts[]
,这样类型信息就不会丢失。