0
votes

I have been using the SymfonyCast on Symfony 4 to try and help me to connect the pieces. I have learned a lot about doctrine Symfony and twig and the environment that they are supposed to work together in. However, that is not what I have to build on. I need to build inside an existing project OpenEMR.

I posted my project code here:

https://github.com/juggernautsei/symfony_twig_doctrine_component/blob/master/library/financialreports/src/FinancialSummaryByInsuranceController.php

The controller works to load the twig template. Now, I am trying to populate the controller with data from the database. I have built the entity class and the repository class. I just can't figure out what to put in this line.

     public function getpaidata($insurerid)
      {
         $payments = $this->repository
     }

To access the class in the repository. The IDE suggested the code in the repository class.

public function getInsurerPaid(ArSession $insurerId)
{
    /*$insurerPaid = $this->_em->getRepository($this->_entityName)->findBy([
        "payer_id" => $insurerId
    ]);*/
    $insurerPaid = $this->findBy([
        'payer_id' => $insurerId
    ]);
    return $insurerPaid;
}

But as I am typing in out the code in the controller, the IDE PHPStorm is not suggesting anything. So, I am stuck. I have tried the suggested code here

https://symfony.com/doc/2.0/book/doctrine.html#creating-an-entity-class https://symfonycasts.com/screencast/symfony-doctrine/repository

but nothing tells me how to access the method that is in the repository class.

UPDATE:

The getpaiddata() method is now changed to

/**
 * @return Fully hydrated object.
 */
public function getpaidata($insurerid)
{
    $row = $this->repository->findBy([
        "payer_id" => $insurerid
    ]);

    return $row;
}
1

1 Answers

1
votes

The problem is likely how you get $this->repository. If you fetch it via the entity manager, via $this->_em->getRepository($entityName) like in the commented snippet, the return value has a type hint which tells the IDE that it is just a generic EntityRepository instead of your custom repository class.

You can install the Symfony-plugin to PhpStorm, which will give you better autocompletion if your entity has the right annotation @Entity(repositoryClass="...").

In a typical Symfony 4 application you could also just inject the correct repository, instead of the EntityManager, e.g. in your constructor:

public function __construct(PaidDataRepository $repository)
{
    $this->repository = $repository;
}

From what it looks like, OpenEMR has it's own way of creating the EntityManager using Connector::instance(). So this will probably not work for you easily, unfortunately.

Another way around this would be to just place a type hint above assigning your variable:

/** @var App\Repository\PaidDataRepository $repository */
$repository = $this->_em->getRepository(PaidData::class)

or, since you have a class variable you can put a similar annotation on there.