sein, also bin ich neu in Symfony und ich habe versucht, eine App mit https://github.com/adesigns/calendar-bundle zu erstellen.Typ Fehler: Argument 1 an AppBundle übergeben EventListener CalendarEventListener :: __ construct() muss eine Instanz von Doctrine ORM EntityManager
Ich habe alle Schritte analysiert in dem CalendarEventListener Erstellung, aber ich habe einen Fehler bekommt:
FatalThrowableError in CalendarEventListener.php line 13: Type error: Argument 1 passed to AppBundle\EventListener\CalendarEventListener::__construct() must be an instance of Doctrine\ORM\EntityManager, instance of Symfony\Bundle\TwigBundle\TwigEngine given, called in /home/intern/Desktop/newapp/var/cache/dev/appDevDebugProjectContainer.php on line 1825
ich durch die Erforschung ähnliche Fragen zu beheben versucht haben, aber ich habe es nicht herausgefunden.
Mein EventCalendarListener:
<?php
namespace AppBundle\EventListener;
use ADesigns\CalendarBundle\Event\CalendarEvent;
use ADesigns\CalendarBundle\Entity\EventEntity;
use Doctrine\ORM\EntityManager;
class CalendarEventListener
{
private $entityManager;
public function __construct(EntityManager $entityManager)
{
$this->entityManager = $entityManager;
}
public function loadEvents(CalendarEvent $calendarEvent)
{
$startDate = $calendarEvent->getStartDatetime();
$endDate = $calendarEvent->getEndDatetime();
// The original request so you can get filters from the calendar
// Use the filter in your query for example
$request = $calendarEvent->getRequest();
$filter = $request->get('filter');
// load events using your custom logic here,
// for instance, retrieving events from a repository
$companyEvents = $this->entityManager->getRepository('AppBundle:MyCompanyEvents')
->createQueryBuilder('company_events')
->where('company_events.event_datetime BETWEEN :startDate and :endDate')
->setParameter('startDate', $startDate->format('Y-m-d H:i:s'))
->setParameter('endDate', $endDate->format('Y-m-d H:i:s'))
->getQuery()->getResult();
// $companyEvents and $companyEvent in this example
// represent entities from your database, NOT instances of EventEntity
// within this bundle.
//
// Create EventEntity instances and populate it's properties with data
// from your own entities/database values.
foreach($companyEvents as $companyEvent) {
// create an event with a start/end time, or an all day event
if ($companyEvent->getAllDayEvent() === false) {
$eventEntity = new EventEntity($companyEvent->getTitle(), $companyEvent->getStartDatetime(), $companyEvent->getEndDatetime());
} else {
$eventEntity = new EventEntity($companyEvent->getTitle(), $companyEvent->getStartDatetime(), null, true);
}
//optional calendar event settings
$eventEntity->setAllDay(true); // default is false, set to true if this is an all day event
$eventEntity->setBgColor('#FF0000'); //set the background color of the event's label
$eventEntity->setFgColor('#FFFFFF'); //set the foreground color of the event's label
$eventEntity->setUrl('http://www.google.com'); // url to send user to when event label is clicked
$eventEntity->setCssClass('my-custom-class'); // a custom class you may want to apply to event labels
//finally, add the event to the CalendarEvent for displaying on the calendar
$calendarEvent->addEvent($eventEntity);
}
}
}
auch meine services.yml
parameters:
# parameter_name: value
services:
app.form_login_authenticator:
class: AppBundle\Security\FormLoginAuthenticator
arguments: ["@router", "@security.password_encoder"]
kernel.listener.allotaxi_exception_listener:
class: AppBundle\EventListener\CalendarEventListener
arguments: ["@templating", "@kernel",]
tags:
- { name: kernel.event_listener, event: kernel.exception, method: onKernelException }
services.xml
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<parameters>
<parameter key="fullcalendar.event.class">ADesigns\CalendarBundle\Entity\EventEntity</parameter>
<parameter key="fullcalendar.loader.event">calendar.load_events</parameter>
</parameters>
</container>
in config.yml alle Dienste
Jede Hilfe importiert werden werden wird geschätzt :)
Klingt wie aus der Fehlermeldung ist der Fehler in appDevDebugProjectContainer.php (Linie 1825), wo Sie den Konstruktor von CalendarEventListener mit dem falschen Argument Typ nennen. – Rob