doctrine entity manager - unable to save data into DB if run through console application

99 views Asked by At

I am working on a batch process and it run via command line. In console application, I use $this->getContainer()->get('doctrine.orm.entity_manager') to get access to doctrine ORM where as from any controller file $emr = $this->getDoctrine()->getManager(); is being used. This second methos won't work for console/command line.

If I try to use any function(functions in controller) which persists or save data into the DB, it is giving error.

private function addActionForReject($docketNumber, $emr)
{
    $mAction = new Action();

    $date = new \DateTime();
    $mAction->setActionId(ConstantRest::NO_FURTHUR_REVIEW_ACTION_ID);
    .....
    $emr->persist($mAction );

    $emr->flush();

Thsi above function exits in a controller and In batch file I have created an instance of that. Using instance I called addActionForReject by passing $emr object that is $this->getContainer()->get('doctrine.orm.entity_manager') in this case.

But this will giving error PHP Fatal error: Call to a member function has() on null in C:\xampp\htdocs\GR\ vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Controller\Controller. php on line 288

NOTE: I am able to fetch data from DB. issue is only when I try to save an object data.

0

There are 0 answers