我有以下错误:Php line 54:Cannot autowire service“App\Repository\Repository”:argument“$entityClass”of method“Doctrine\Bundle\DoctrineBundle\Repository\ServiceRepository::_construct()”has no type-hint,you should configure its value
明确地。
我的课程:
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\EmployeeRepository")
*/
class Employee extends User
{
}
<?php
namespace App\Controller;
use App\Entity\Employee;
use App\Entity\EmployeeBoss;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class EmployeeController extends AbstractController
{
/**
* @return Response
* @Route('/employees')
*/
public function getEmployees(): Response
{
$employees = $this->getDoctrine()->getRepository(Employee::class)->findAll();
if(!$employees){
return new Response(null);
}
$formatted = [];
foreach ($employees as $employee){
$formatted[] = $this->getDoctrine()->getRepository(Employee::class)->getDetails($employee);
}
return new Response($formatted);
}
<?php
namespace App\Repository;
use App\Entity\Employee;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
class EmployeeRepository extends ServiceEntityRepository
{
public function getDetails(Employee $employee)
{
return [
'id' => $employee->getId(),
'firstname' => $employee->getFirstname(),
'lastname' => $employee->getLastname(),
'email' => $employee->getEmail(),
'password' => $employee->getPassword(),
'startDate' => $employee->getStartDate(),
'endDate' => $employee->getEndDate(),
];
}
}
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping\MappedSuperclass;
use Doctrine\ORM\Mapping as ORM;
use DateTime;
/**
* @MappedSuperclass
*/
class User
{
/**
* @ORM\Id()
* @ORM\Column(type="integer")
* @ORM\GeneratedValue()
*/
private $id;
/**
* @ORM\Column(type="string")
*/
private $firstname;
/**
* @ORM\Column(type="string")
*/
private $lastname;
/**
* @ORM\Column(type="string")
*/
private $email;
/**
* @ORM\Column(type="string")
*/
private $password;
/**
* @ORM\Column(type="datetime")
*/
private $startDate;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $endDate;
/**
* @param int $id
*/
public function setId(int $id)
{
$this->id = $id;
}
/**
* @return int
*/
public function getId(): int
{
return $this->id;
}
/**
* @param string $email
*/
public function setEmail(string $email)
{
$this->email = $email;
}
/**
* @return string
*/
public function getPassword(): string
{
return $this->password;
}
/**
* @return string
*/
public function getEmail(): string
{
return $this->email;
}
/**
* @return string
*/
public function getLastname():string
{
return $this->lastname;
}
/**
* @return string
*/
public function getFirstname(): string
{
return $this->firstname;
}
/**
* @param string $password
*/
public function setPassword(string $password)
{
$this->password = $password;
}
/**
* @param string $lastname
*/
public function setLastname(string $lastname)
{
$this->lastname = $lastname;
}
/**
* @param string $firstname
*/
public function setFirstname(string $firstname)
{
$this->firstname = $firstname;
}
/**
* @return DateTime
*/
public function getEndDate(): ?DateTime
{
return $this->endDate;
}
/**
* @return DateTime
*/
public function getStartDate(): DateTime
{
return $this->startDate;
}
/**
* @param DateTime $endDate
*/
public function setEndDate(?DateTime $endDate)
{
$this->endDate = $endDate;
}
/**
* @param DateTime $startDate
*/
public function setStartDate(DateTime $startDate)
{
$this->startDate = $startDate;
}
}
1条答案
按热度按时间7tofc5zh1#
错误已经在说了:
根据文档中的要求,将正确的参数传递给构造函数。查询对象:存储库
错误:
“Doctrine\Bundle\DoctrineBundle\Repository ServiceRepository::__construct()”没有类型提示
由于
ServiceEntityRepository
需要它属于哪个实体类型,因此需要通过引用进行类型提示,因此我们需要将类名指定给构造函数。