所以我是新进入Symfony,我一直在尝试使用https://github.com/adesigns/calendar-bundle创建应用程序。类型错误:参数1传递给AppBundle EventListener CalendarEventListener :: __ construct()必须是Doctrine ORM EntityManager的一个实例
我已经解析了所有的步骤到创建CalendarEventListener但我有一个错误:
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
我试图通过研究类似的问题来解决,但我不理解了它。
我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);
}
}
}
也是我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>
在config.yml所有服务都是进口
任何帮助将不胜感激:)
听起来像是从错误信息的错误是在调用CalendarEventListener与错误的参数类型的构造appDevDebugProjectContainer.php(线1825)。 – Rob