In my Data Repository I created a function:
public function myData(){
$data = $this->createQueryBuilder('data')
->leftJoin('data.fields', 'f')
->andWhere('f.name = :field')
->setParameter('field', 'company');
$result = $data->getQuery()->execute();
return $result;
}
In my Controller I want to use this function:
class PagesController extends AbstractController
{
public function __construct(EntityManagerInterface $em) {
$this->em = $em;
}
/**
* @Route("/page", name="page", methods={"POST", "GET"})
*/
public function page(Request $request)
{
$data = $this->em->getRepository('App\Entity\Data')->myData();
But I get the error message:
Undefined method ‘myData’. The method name must start with either
findBy, findOneBy or countBy!
2
Answers
You should inject your repository in your controller:
In your myData function your using variable called $data but then in $result your using $qb…
You should change $data by $qb