charliepage88
charliepage88

Reputation: 95

Symfony Service setting NULL data

I've been having several issues with creating a service in Symfony 2.0, but have found workarounds for everything but the service setting null data.

public function logAction($request, $entityManager)
{
    $logs = new Logs();
    $logs->setRoute = $request->get('_route');
    $logs->setController = $request->get('_controller');
    $logs->setRequest = json_encode($request->attributes->all());
    $logs->setPath = $request->server->get('PATH_INFO');
    $logs->setIp = $request->server->get('REMOTE_ADDR');

    $em = $entityManager;
    $em->persist($logs);
    $em->flush();
}

I'm passing the EntityManager when calling the service in another controller, I'll post that code just in case:

public function pageAction($id = null, Request $request)
{
    $log = $this->get('logging');
    $log->logAction($request, $this->getDoctrine()->getEntityManager());

    return $this->render('AcmeDemoBundle:Demo:viewPage.html.twig', array('name' => $id));
}

I have created a services.yml file following the official docs (in the Log Bundle) and an actual row is inserted, but all fields are set to NULL. If I try to do a die in one of the setters in the entity file it doesn't die, so it seems like something isn't making it. (I have both the EntityManager and Entity files used at the top of the log service file before anyone asks)

Any help would be greatly appreciated.

Upvotes: 0

Views: 427

Answers (1)

Cerad
Cerad

Reputation: 48865

$logs->setRoute = $request->get('_route');

Should be:

$logs->setRoute($request->get('_route'));

For D2 all the accessors need to be methods.

Upvotes: 2

Related Questions