I create service for add formType then persist object and in controller I invoke data but I have error shown on below image:
in controller i extend class abstractController content getHandler and I have view newskill.html.twig
Code SkillController.php:
<?php
namespace AppBundle\Controller\Condidate;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use AppBundle\Entity\Skill;
use AppBundle\Controller\AbstractController;
use AppBundle\Form\SkillType;
/**
*Class SkillController.
*/
class SkillController extends AbstractController
{
/**
*function handler.
*/
protected function getHandler(){
//var_dump('test');
}
/**
*function addSkill
* #param Request $request
* #return \Symfony\Component\Form\Form The form
*/
public function addSkillAction(Request $request) {
$skill = $this->getHandler()->post();
if ($skill instanceof \AppBundle\Entity\Skill) {
return $this->redirectToRoute('ajouter_info');
}
return $this->render('skills/newskill.html.twig', array(
'form' => $form->createView(),));
}
}
Code SkillHandler.php:
<?php
namespace AppBundle\Handler;
use AppBundle\Handler\HandlerInterface;
use Symfony\Component\HttpFoundation\Request;
use AppBundle\Entity\Skill;
use Doctrine\ORM\EntityManager;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\Form\formFactory;
/**
* SkillHandler.
*/
class SkillHandler implements HandlerInterface {
/**
*
* #var EntityManager
*/
protected $em;
/**
*
* #var formFactory
*/
private $formFactory;
/**
*function construct.
*/
public function __construct(EntityManager $entityManager, formFactory $formFactory)
{
$this->em = $entityManager;
$this->formFactory = $formFactory;
}
/**
*function post
*/
public function post(array $parameters, array $options = []) {
$form = $this->formFactory->create(\AppBundle\Form\SkillType::class, $object, $options);
$form->submit($parameters);
if ($form->isValid()) {
$skill = $form->getData();
$this->persistAndFlush($skill);
return $skill;
}
return $form->getData();
}
/**
*function persisteAndFlush
*/
protected function persistAndFlush($object) {
$this->em->persist($object);
$this->em->flush();
}
/**
*function get
*/
public function get($id){
throw new \DomainException('Method SkillHandler::get not implemented');
}
/**
*function all
*/
public function all($limit = 10, $offset = 0){
throw new \DomainException('Method SkillHandler::all not implemented');
}
/**
*function put
*/
public function put($resource, array $parameters, array $options){
throw new \DomainException('Method SkillHandler::put not implemented');
}
/**
*function patch
*/
public function patch($resource, array $parameters, array $options){
throw new \DomainException('Method SkillHandler::patch not implemented');
}
/**
*function delete
*/
public function delete($resource){
throw new \DomainException('Method SkillHandler::delete not implemented');
}
}
code services.yml:
skill_add:
class: AppBundle\Handler\SkillHandler
arguments:
- "#doctrine.orm.entity_manager"
- "#form.factory"
public: true
Any help would be appreciated.
Your $this->getHandler() retruns null.
Solution can be checking if $this->getHandler() doesn't return null in first place.
if (!$this->getHandler()) {
throw new \Exception(sprintf('Handler cannot be null')
} else {
$skill = $this->getHandler()->post();
}
Try this, firstly you should take your handler into getHandler() method at your Controller.
protected function getHandler(){
return $this->get('skill_add');
}
Related
im learning symfony. I have a twig using twig extension and i found that i cannot call a function from other controller inside twig extension.
so i have decide to use a service since the twig extension is using the service.
so i tried to call a function from controller in the service and call the function from the service in the twig extension.
Then, i have an error message that [Call to a member function has() on null], where $doct = $this->getDoctrine()->getManager(); in the controller.
this is the function in the controller that i'm trying to use
edited
namespace Customize\Controller;
use Customize\Entity\CustomRing;
use Customize\Entity\Ring;
use Customize\Repository\CustomProductRepository;
use Eccube\Controller\AbstractController;
use Eccube\Entity\BaseInfo;
use Eccube\Entity\Product;
use Eccube\Entity\ProductClass;
use Eccube\Event\EccubeEvents;
use Eccube\Event\EventArgs;
use Eccube\Repository\BaseInfoRepository;
use Eccube\Repository\ProductClassRepository;
use Eccube\Service\CartService;
use Eccube\Service\OrderHelper;
use Eccube\Service\PurchaseFlow\PurchaseContext;
use Eccube\Service\PurchaseFlow\PurchaseFlow;
use Eccube\Service\PurchaseFlow\PurchaseFlowResult;
use Google\Service\Monitoring\Custom;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
class CartController extends AbstractController
{
/**
* #var ProductClassRepository
*/
protected $productClassRepository;
/**
* #var CartService
*/
protected $cartService;
/**
* #var PurchaseFlow
*/
protected $purchaseFlow;
/**
* #var BaseInfo
*/
protected $baseInfo;
/**
* #var CustomProductRepository
*/
protected $customProductRepository;
/**
* CartController constructor.
*
* #param ProductClassRepository $productClassRepository
* #param CartService $cartService
* #param PurchaseFlow $cartPurchaseFlow
* #param BaseInfoRepository $baseInfoRepository
* #param CustomProductRepository $customProductRepository
*/
public function __construct(
ProductClassRepository $productClassRepository,
CartService $cartService,
PurchaseFlow $cartPurchaseFlow,
BaseInfoRepository $baseInfoRepository,
CustomProductRepository $customProductRepository
) {
$this->productClassRepository = $productClassRepository;
$this->cartService = $cartService;
$this->purchaseFlow = $cartPurchaseFlow;
$this->baseInfo = $baseInfoRepository->get();
$this->customProductRepository = $customProductRepository;
}
public function image_route(){
$Carts = $this->cartService->getCarts();
$doct = $this->getDoctrine()->getManager();
$custom_images = array();
$Custom_product = $this->customProductRepository->customProductFindByName();
$Product = $doct->getRepository(Product::class)->find($Custom_product[0]->getId());
foreach ($Carts as $Cart) {
$items = $Cart->getCartItems();
foreach($items as $item ){
if($item->getProductClass()->getProduct()->getId() == $Product->getId()){
$custom = $item->getProductClass()->getCode();
$custom = $doct->getRepository(CustomRing::class)->find($custom);
$ring = $doct->getRepository(Ring::class)->find($custom->getRingBaseId());
$upload_directory= $this->getParameter('uploads_directory');
$ring_shape = $ring->getRingShape();
$ring_type = $ring->getRingType();
$upload = $upload_directory.'/customRing/ring/'.$ring_shape.'/'.$ring_type.'/';
$images = glob($upload."*.{jpg,png,jpeg,JPG,JPEG,PNG}", GLOB_BRACE);
for($i=0;$i<count($images);$i++){
$aa = explode('save_image/', $images[$i]);
$images[$i] = $aa[1];
}
array_push($custom_images,$images[0]);
}
}
}
return $custom_images;
use Customize\Controller\CartController;
/**
* #var CartController
*/
protected $cartController;
public function __construct(
SessionInterface $session,
EntityManagerInterface $entityManager,
ProductClassRepository $productClassRepository,
CartRepository $cartRepository,
CartItemComparator $cartItemComparator,
CartItemAllocator $cartItemAllocator,
OrderRepository $orderRepository,
TokenStorageInterface $tokenStorage,
AuthorizationCheckerInterface $authorizationChecker,
CartController $CartController
) {
$this->session = $session;
$this->entityManager = $entityManager;
$this->productClassRepository = $productClassRepository;
$this->cartRepository = $cartRepository;
$this->cartItemComparator = $cartItemComparator;
$this->cartItemAllocator = $cartItemAllocator;
$this->orderRepository = $orderRepository;
$this->tokenStorage = $tokenStorage;
$this->authorizationChecker = $authorizationChecker;
$this->cartController = $CartController;
}
/*other functions
.
.
*/
public function imagess(){
$temp = $this->cartController->image_route();
return $temp;
}
and this is the twig extension
use Eccube\Service\CartService;
class CartServiceExtension extends AbstractExtension
{
/**
* #var CartService
*/
protected $cartService;
public function get_image_route(){
$t = $this->cartService->imagess();
return $t;
//return ['11', '12'];
}
}
The line i got error in controller is
$doct = $this->getDoctrine()->getManager();
and when go inside getDoctrine()
trait ControllerTrait{
/**
* Shortcut to return the Doctrine Registry service.
*
* #return ManagerRegistry
*
* #throws \LogicException If DoctrineBundle is not available
*
* #final
*/
protected function getDoctrine()
{
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 know why but it seems has() function inside getDoctrine() returns null
how can i use the function from the controller so that i can pass the values of $custom_images into the twig?
To get Doctrine in any controller action, you can do away with that function/trait entirely and just inject the EntityManagerInterface into your action.
For example:
class SomeCustomController extends AbstractController
{
public function someControllerAction(Request $request, EntityManagerInterface $em): Response
{
// business logic
}
}
I'm creating a website with Symfony 5. I have a problem that I can't solve.
I need to be able to create entities and for that I want to use a form generated by Symfony.
Symfony sends me this error:
Can use "yield from" only with arrays and Traversables
If I modify anything in my "Entities" entity then symfony sends me back:
My field I was waiting for
Great, that's exactly what I need, but the problem is that if I refresh the page the error comes back.
<?php
namespace App\Controller\Admin;
use App\Entity\Entities;
use App\Entity\Events;
use App\Form\EntitiesType;
use App\Form\EventsType;
use App\Repository\CriteriasRepository;
use App\Repository\EntitiesRepository;
use App\Repository\EventsRepository;
use Doctrine\Persistence\ObjectManager;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
Class AdminHome extends AbstractController {
protected $event;
protected $entity;
protected $criteria;
protected $twig;
public function __construct(EventsRepository $event, EntitiesRepository $entity, CriteriasRepository $criteria, ObjectManager $em)
{
$this->event = $event;
$this->entity = $entity;
$this->criteria = $criteria;
$this->em = $em;
}
public function index(){
$event = $this->event->findOneBy(['current' => 1]);
$criterias = $this->indexCriteria($event);
$entities = $this->indexEntity($event);
return new Response($this->render('admin/home.html',[ 'event' => $event, 'entities' => $entities, 'criterias' => $criterias ]));
}
public function indexEntity(Events $event){
return $event->getEntity();
}
public function indexCriteria(Events $event){
return $event->getCriterias();
}
/**
* #Route("/admin/event/create", name="admin.event.new")
*/
public function newEvent(Request $request){
$event = new Events();
$form = $this->createForm(EventsType::class, $event);
$form->handleRequest($request);
if($form->isSubmitted() && $form->isValid()){
$this->em->persist($event);
$this->em->flush();
return $this->redirectToRoute('adminHome');
}
return $this->render('admin/event/eventNew.html', ['event' => $event, 'form' => $form->createView()]);
}
/**
* #Route("/admin/entity/create", name="admin.entity.new")
*/
public function newEntity(Request $request){
$entity = new Entities();
$form = $this->createForm(EntitiesType::class, $entity);
$form->handleRequest($request);
if($form->isSubmitted() && $form->isValid()){
$this->em->persist($entity);
$this->em->flush();
return $this->redirectToRoute('adminHome');
}
return $this->render('admin/entity/entityNew.html', ['entity' => $entity, 'form' => $form->createView()]);
}
// /**
// * #Route("/admin/entity/edit", name="admin.entity.edit")
// */
// public function editEntity(Entities $entity, Request $request){
// $form = $this->createForm(EntityType::class, $entity);
// $form->handleRequest($request);
// if($form->isSubmitted() && $form->isValid()){
// $this->em->flush();
// return $this->redirectToRoute('adminHome');
// }
// return $this->render('admin/entityEdit.html', ['entity' => $entity, 'form' => $form->createView()]);
// }
}
?>
<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity(repositoryClass=EntitiesRepository::class)
*/
class Entities
{
/**
* #ORM\Id
* #ORM\GeneratedValue
* #ORM\Column(type="integer")
*/
private $id;
/**
* #ORM\Column(type="string", length=255)
*/
private $entityName;
/**
* #ORM\OneToMany(targetEntity=Rates::class, mappedBy="entity")
*/
private $rates;
/**
* #ORM\ManyToMany(targetEntity=Events::class, mappedBy="entity")
*/
private $event;
/**
* #ORM\Column(type="string", length=255)
*/
private $descriptionFr;
/**
* #ORM\Column(type="string", length=255, nullable=true)
*/
private $descriptionEn;
/**
* #ORM\ManyToMany(targetEntity=Themes::class, inversedBy="entities")
*/
private $theme;
public function __construct()
{
$this->rates = new ArrayCollection();
$this->event = new ArrayCollection();
$this->theme = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getEntityName(): ?string
{
return $this->entityName;
}
public function setEntityName(string $entityName): self
{
$this->entityName = $entityName;
return $this;
}
/**
* #return Collection|Rates[]
*/
public function getRates(): Collection
{
return $this->rates;
}
public function addRate(Rates $rate): self
{
if (!$this->rates->contains($rate)) {
$this->rates[] = $rate;
$rate->setEntity($this);
}
return $this;
}
public function removeRate(Rates $rate): self
{
if ($this->rates->removeElement($rate)) {
// set the owning side to null (unless already changed)
if ($rate->getEntity() === $this) {
$rate->setEntity(null);
}
}
return $this;
}
/**
* #return Collection|Events[]
*/
public function getEvent(): Collection
{
return $this->event;
}
public function addEvent(Events $event): self
{
if (!$this->event->contains($event)) {
$this->event[] = $event;
$event->addEntity($this);
}
return $this;
}
public function removeEvent(Events $event): self
{
if ($this->event->removeElement($event)) {
$event->removeEntity($this);
}
return $this;
}
public function getDescriptionFr(): ?string
{
return $this->descriptionFr;
}
public function setDescriptionFr(string $descriptionFr): self
{
$this->descriptionFr = $descriptionFr;
return $this;
}
public function getDescriptionEn(): ?string
{
return $this->descriptionEn;
}
public function setDescriptionEn(?string $descriptionEn): self
{
$this->descriptionEn = $descriptionEn;
return $this;
}
/**
* #return Collection|Themes[]
*/
public function getTheme(): Collection
{
return $this->theme;
}
public function addTheme(Themes $theme): self
{
if (!$this->theme->contains($theme)) {
$this->theme[] = $theme;
}
return $this;
}
public function removeTheme(Themes $theme): self
{
$this->theme->removeElement($theme);
return $this;
}
}
<?php
namespace App\Form;
use App\Entity\Entities;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class EntitiesType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('entityName')
->add('descriptionFr' )
->add('descriptionEn')
->add('event')
->add('theme')
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Entities::class,
]);
}
}
{{ form_start(form) }}
{{ form_rest(form) }}
<button class="btn">{{ button|default('Créer')}}</button>
{{ form_end(form) }}
This function is in helper I am using zf2 version 2.4 I am beginner in zend please help me.
I tried this:
function getUrlArray(){
$helperUrl = new Url(); // use Zend\View\Helper\Url;
$op = $helperUrl->url();
print_r($op);
}
I am getting this error:
Fatal error: Call to undefined method Zend\View\Helper\Url::url()
Try this ViewHelper :
<?php
namespace YourNamespace\View\Helper\Service;
use YourNamespace\View\Helper\CurrentUri;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
class CurrentUriFactory implements FactoryInterface
{
/**
* #param ServiceLocatorInterface $serviceLocator
* #return CurrentUri
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$helper = new CurrentUri();
$helper->setRequest($serviceLocator->getServiceLocator()->get('Request'));
return $helper;
}
}
<?php
namespace YourNamespace\View\Helper;
use Zend\Stdlib\RequestInterface;
use Zend\View\Helper\AbstractHelper;
/**
* Helper: $this->currentUri();
*/
class CurrentUri extends AbstractHelper
{
/**
* #var \Zend\Http\PhpEnvironment\Request
*/
protected $request;
/**
* #return string
* #see \Zend\Http\PhpEnvironment\Request
* #see \Zend\Uri\Uri
*/
public function __invoke()
{
return $this->getRequest()->getUri()->toString();
}
/**
* #return \Zend\Http\PhpEnvironment\Request
*/
public function getRequest()
{
return $this->request;
}
/**
* #param RequestInterface $request
* #return CurrentUri
*/
public function setRequest(RequestInterface $request)
{
$this->request = $request;
return $this;
}
}
I have a custom repository in my Symfony's project and I want use like a search tool. My project' structure is the following:
P.D. UPDATED Question and code
-Manager:
* BaseManager.php
* MyEntityManager.php
-Repository:
* BaseRepository.php
* MyEntityRepository.php
Well, I want access to my custom repository and use the following method findByTitle, which method should return an array with objects which description field be similar. I put a simple print (var_dump of the term entered) inside of my function to see if my browser shows it, but it isn't showed yet...
My BaseManager:
<?php
namespace AppBundle\Manager;
use AppBundle\Repository\BaseRepository;
class BaseManager
{
/**
* #var BaseRepository
*/
protected $repo;
/**
* #param BaseRepository $repo
*/
public function __construct(BaseRepository $repo)
{
$this->repo = $repo;
}
/**
* #param $model
* #return bool
*/
public function create($model)
{
return $this->repo->create($model);
}
/**
* #param CrudModel $model
* #return bool
*/
public function update($model)
{
return $this->repo->save($model);
}
/**
* #param CrudModel $model
* #return bool
*/
public function delete($model)
{
return $this->repo->delete($model);
}
/**
* #param $id
* #return null|object
*/
public function getOneById($id)
{
return $this->repo->findOneById($id);
}
/**
* #return array
*/
public function all()
{
return $this->repo->all();
}
}
MyEntityManager:
<?php
namespace AppBundle\Manager;
use AppBundle\Repository\MyEntityRepository;
use AppBundle\Entity\MyEntity;
/**
* Class MyEntityManager
* #package AppBundle\Manager
*/
class MyEntityManager extends BaseManager{
public function findByTitle($title){
echo '<h1>flux of code here</h1>';
return $this->repo->findByTitle($title);
}
public function findSimilars($term){
echo '<h1>flux of code here</h1>';
return $this->repo->findSimilars($term);
}
}
BaseRepository:
<?php
namespace AppBundle\Repository;
use Doctrine\ORM\EntityRepository;
abstract class BaseRepository extends EntityRepository
{
public function create($model, $autoFlush = true)
{
return $this->insert($model,$autoFlush);
}
public function save($model, $autoFlush = true)
{
return $this->insert($model,$autoFlush);
}
public function delete($model)
{
try{
$this->getEntityManager()->remove($model);
$this->getEntityManager()->flush();
return true;
}catch (\Exception $e){
echo $e->getMessage();
}
}
public function findOneById($id)
{
return $this->findOneBy(array('id' => $id));
}
public function all()
{
return $this->findAll();
}
private function insert($model, $autoFlush = true)
{
$this->getEntityManager()->persist($model);
if ($autoFlush) {
$this->getEntityManager()->flush();
return true;
}
}
}
MyEntityRepository:
<?php
namespace AppBundle\Repository;
use Doctrine\ORM\EntityRepository;
/**
* Class MyEntityRepository
* #package AppBundle\Repository
*/
class MyEntityRepository extends BaseRepository{
private function findById($id){
$query = $this->createQueryBuilder('myentity')
->where('myentity.id = :id')
->setParameter('id', $id)
->getQuery();
$myentity = $query->getResult();
return $myentity;
}
private function findByTitle($term){
echo '<h1>';
var_dump($term);
echo '</h1>',
$query = $this->createQueryBuilder('myentity')
->andwhere('myentity.description = :description')
->setParameter('description', $term)
->getQuery();
$myentity = $query->getResult();
return $myentity;
}
}
The beginning of MyEntity:
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* #ORM\Table(name="myentity")
* #ORM\Entity
* #ORM\Entity(repositoryClass="AppBundle\Repository\MyEntityRepository")
*/
class MyEntity {
......
My services.yml:
parameters:
app.myentity.repository.class: AppBundle\Repository\MyEntityRepository
app.myentity.manager.class: AppBundle\Manager\MyEntityManager
services:
app.myentity.repository:
class: %app.myentity.repository.class%
public: true
factory_service: doctrine.orm.entity_manager
factory_method: getRepository
arguments: [ AppBundle\Entity\MyEntity ]
app.myentity.manager:
class: %app.myentity.manager.class%
arguments: [#app.myentity.repository]
And I'm calling my service in the following way:
public function searchAction(Request $request, $term){
$manager = $this->get('app.myentity.manager');
$result = $manager->findByTitle($term);
echo '<h5>';
var_dump($result);
echo '</h5>';
....
}
Just a guess, as your question is far from being clear (esp. the last paragraph): did you only register the service, or did you also tell Symfony to use the repository for the entity (presumably MyEntity)? For instance, using annotations, you’d need something like this:
#ORM\Entity(repositoryClass="The\RepositoryClass")
The problem was that I declared my function as private instead of public
private function findByTitle($term){
instead of
public function findByTitle($term){
Im trying to insert data into database in onKernelRequest using doctrine
//** src/MPN/CRMBundle/Listener/AnalyticsListener.php
namespace MPN\CRMBundle\Listener;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use MPN\CRMBundle\Manager\AnalyticsManager;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\Response;
use Doctrine\ORM\EntityManager;
use vRonn\StatisticsBundle\Entity\Statistics as Statistics;
class AnalyticsListener
{
/**
* #var AnalyticsManager
*/
private $am;
private $em;
public function __construct(AnalyticsManager $am)
{
$this->am = $am;
}
public function onKernelRequest(GetResponseEvent $event)
{
if (!$event->isMasterRequest()) {
return;
}
$request = $event->getRequest();
$session = $request->getSession();
$uri = $request->getRequestUri();
$route = $request->get('_route');
if (!preg_match('#^/(app_dev\.php/)?(admin|js|media|_[^/]+)/?.*#', $uri)) {
// add page view count
$this->am->addPageView();
//Here is how i try to insert data
$d = new Statistics();
$d->setType(1);
$d->setName('blabla');
$d->setValue('val');
$em = $this->am->em->getRepository('vRonnStatisticsBundle:Statistics');
$em->persist($d);
$em->flush();
if (!$session->has('visitor') || $session->get('visitor') < time()) {
$session->set('visitor', time() + (24 * 60 * 60));
$this->am->addVisitor();
}
$this->am->save();
}
}
but i get error below
Undefined method 'persist'. The method name must start with either
findBy or findOneBy!
Here is the manager which i take the entity manager from, i take entity from here because i tried both $this->get('doctrine') or $this->getDoctrine() inside onKernelRequest but error
//** src/MPN/CRMBundle/Manager/AnalyticsManager.php
namespace MPN\CRMBundle\Manager;
use Doctrine\ORM\EntityManager;
use MPN\CRMBundle\Entity\Analytics;
use MPN\CRMBundle\Service\DateTimeBuilder;
class AnalyticsManager
{
/**
* #var EntityManager
*/
public $em;
/**
* #var DateTimeBuilder
*/
private $dateTimeBuilder;
/**
* #var array
*/
private $analytics;
public function __construct(EntityManager $em, DateTimeBuilder $dateTimeBuilder)
{
$this->em = $em;
$this->dateTimeBuilder = $dateTimeBuilder;
$this->setup();
}
/**
* Flushes the data to the database.
*
* #return void
*/
public function save()
{
$this->em->flush();
}
}
It looks like you're setting $em to a repository, not an entity manager. If you just do $em = $this->am->em it oughta work.