I trying to use the bundle JMS Serializer in symfony v4.20.5.
I had install the package composer require jms/serializer-bundle
.
I added the bundle in file config/bundles.php JMSSerializerBundleJMSSerializerBundle::class=> ['all' => true],
.
Now in my _construct method of my Controller i did thhat:
<?php
namespace AppController;
use AppTraitsProjectTrait;
use DoctrineORMEntityManagerInterface;
use JMSSerializerSerializer;
use SymfonyBundleFrameworkBundleControllerAbstractController;
use SymfonyComponentHttpFoundationResponse;
use SymfonyContractsEventDispatcherEventDispatcherInterface;
class BaseController extends AbstractController
{
use ProjectTrait;
/**
* @var EventDispatcherInterface
*/
protected $eventDispatcher;
/**
* @var EntityManagerInterface
*/
protected $em;
/**
* @var Serializer|object
*/
protected $serializer;
/**
* BaseController constructor.
* @param EventDispatcherInterface $eventDispatcher
* @param EntityManagerInterface $em
*/
public function __construct(EventDispatcherInterface $eventDispatcher, EntityManagerInterface $em)
{
$this->eventDispatcher = $eventDispatcher;
$this->em = $em;
$this->serializer = $this->get('jms_serializer');
}
public function index(): Response{
return $this->render('dashboards/default_dashboard.html.twig');
}
}
But in my navigator i get that : Call to a member function get() on null
This error refers to the get function of AbstractContainer :
protected function get(string $id): object
{
return $this->container->get($id);
}
I can not correct this error. thank you for helping me.
Source: Symfony Questions
Was this helpful?
0 / 0