0

I try to call "class CltvController" from another class like this :

class StatLtvcController extends AbstractController
{
$cltv_temp = new CltvController();
return $this->render('admin/statltvc.html.twig', [ 'cltv_temp' => $cltv_temp->cltv(),        ]);
}

but this class :

namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use App\Entity\Game;
use App\Entity\Adventure;
use Symfony\Component\Routing\Annotation\Route;

class CltvController extends AbstractController
{

public function cltv(): float{

    $periodh = '2021-06-01'; // $request->request->get('')
    $periodi = '2021-07-31'; // $request->request->get('')

    $em = $this->getDoctrine()->getManager();
    $con = $em->getRepository(Game::class);        
    $con3 = $em->getRepository(Adventure::class);  

    $ncnt[] = $con->findByCountncn($periodh,$periodi);
    $nadvt[] = $con3->findByCountadv($periodh,$periodi);             
           
    return $nadvt[0][0][1]/$ncnt[0][0][1];

}

}

is returning this error :

Call to a member function has() on null

Error
in G:\Mes_TPs\TP_Symfony_PHP\Quaestyo\vendor\symfony\framework-bundle\Controller  \AbstractController.php (line 345)

     *
     * @throws \LogicException If DoctrineBundle is not available
     */
    protected function getDoctrine(): ManagerRegistry
    {
        if (!$this->container->has('doctrine')) {
            throw new \LogicException('The DoctrineBundle is not registered in your application. Try running "composer require symfony/orm-pack".');
        }
        return $this->container->get('doctrine');
    }

I don't understand why $this->getDoctrine is returning an error?

bad_coder
  • 11,289
  • 20
  • 44
  • 72

2 Answers2

0

Try to add this bloc over CltvController class:

/**
 * @method getDoctrine()
 */
class CltvController extends AbstractController {

• If that didn't work, can you tell me the exact version of php & symfony of your project please?

Khribi Wessim
  • 287
  • 2
  • 12
0

Thanks for your answer. It's the same error message with your solution.Actually, Symfony is calling getDoctrine() in the class StatLtvcController. (i didn't put all because code was too long). How could i call getdoctrine() in the class CltvController ? I use last versions : PHP 7.4.9 and Symfony 5.2.14

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-ask). – Community Sep 14 '21 at 10:19