没有找到的方法,所以我无法从DB获取事件

时间:2018-01-17 12:59:05

标签: php symfony

我使用adesigns / calendar-bundle在我的symfony项目上创建日历。 当我访问fc-load-events时,我无法从数据库中获取事件,这是我的实体监听器:

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('CMRBundle:EventEntity')
            ->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);
        }
    }
}

这是我得到的错误:

if ($companyEvent->getAllDayEvent() === false) {
$eventEntity = new EventEntity($companyEvent->getTitle(), $companyEvent->getStartDatetime(), $companyEvent->getEndDatetime());
} else {
$eventEntity = new EventEntity($companyEvent->getTitle(), $companyEvent->getStartDatetime(), null, true);
}

所有方法都是找不到:`getAllDayEvent(),getTitle(),getStartDatetime()。

我的实体中有一个公共函数getDaterdv:

(我已将实体更改为)RDV:

<?php

namespace CMRBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * RDV
 *
 * @ORM\Table(name="r_d_v")
 * @ORM\Entity(repositoryClass="CMRBundle\Repository\RDVRepository")
 */
class RDV
{
 /**
 * @var int
 *
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
private $id;

/**
 * @var \DateTime
 *
 * @ORM\Column(name="datecrea", type="datetime")
 */
private $datecrea;

/**
  * @ORM\Column(name="published", type="boolean")
  */
private $published = true;

/**
 * @var \DateTime
 *
 * @ORM\Column(name="daterdv", type="datetime")
 */
private $daterdv;

/**
 * @var string
 *
 * @ORM\Column(name="title", type="string", length=255)
 */
private $title;


/**
 * @var string
 *
 * @ORM\Column(name="agentname", type="string", length=255)
 */
private $agentname;


/**
 * @var string
 *
 * @ORM\Column(name="qualif", type="string", length=255)
 */
private $qualif;

/**
 * @var int
 *
 * @ORM\Column(name="agentid", type="integer")
 */
private $agentid;

/**
 * @var string
 *
 * @ORM\Column(name="company", type="string", length=255)
 */
private $company;

/**
 * @var string
 *
 * @ORM\Column(name="comname", type="string", length=255)
 */
private $comname;

/**
 * @var text
 *
 * @ORM\Column(name="content", type="text")
 */
private $content;

/**
 * @var text
 *
 * @ORM\Column(name="adresse", type="text")
 */
private $adresse;

/**
 * @var text
 *
 * @ORM\Column(name="ville", type="text")
 */
private $ville;

/**
 * @var text
 *
 * @ORM\Column(name="telfixe", type="text")
 */
private $telfixe;

/**
 * @var text
 *
 * @ORM\Column(name="telpor", type="text")
 */
private $telpor;

/**
 * @var text
 *
 * @ORM\Column(name="tarif", type="text")
 */
private $tarif;

/**
 * @var text
 *
 * @ORM\Column(name="support", type="text")
 */
private $support;

public function __construct()
{
$this->datecrea = new \Datetime();
$this->daterdv = new \DateTime();
}

/**
 * Get id
 *
 * @return int
 */
public function getId()
{
    return $this->id;
}

/**
 * Set datecrea
 *
 * @param \DateTime $datecrea
 *
 * @return RDV
 */
public function setDatecrea($datecrea)
{
    $this->datecrea = $datecrea;

    return $this;
}

/**
 * Get datecrea
 *
 * @return \DateTime
 */
public function getDatecrea()
{
    return $this->datecrea;
}

/**
 * Set daterdv
 *
 * @param \DateTime $daterdv
 *
 * @return RDV
 */
public function setDaterdv($daterdv)
{
    $this->daterdv = $daterdv;

    return $this;
}

/**
 * Get daterdv
 *
 * @return \DateTime
 */
public function getDaterdv()
{
    return $this->daterdv;
}

/**
 * Set title
 *
 * @param string $title
 *
 * @return RDV
 */
public function setTitle($title)
{
    $this->title = $title;

    return $this;
}

/**
 * Get title
 *
 * @return string
 */
public function getTitle()
{
    return $this->title;
}

/**
 * Set agentid
 *
 * @param integer $agentid
 *
 * @return RDV
 */
public function setAgentid($agentid)
{
    $this->agentid = $agentid;

    return $this;
}

/**
 * Get agentid
 *
 * @return int
 */
public function getAgentid()
{
    return $this->agentid;
}

/**
 * Set company
 *
 * @param string $company
 *
 * @return RDV
 */
public function setCompany($company)
{
    $this->company = $company;

    return $this;
}

/**
 * Get company
 *
 * @return string
 */
public function getCompany()
{
    return $this->company;
}


/**
 * Set content
 *
 * @param string $content
 *
 * @return RDV
 */
public function setContent($content)
{
    $this->content = $content;

    return $this;
}

/**
 * Get content
 *
 * @return string
 */
public function getContent()
{
    return $this->content;
}

/**
 * Set published
 *
 * @param boolean $published
 *
 * @return RDV
 */
public function setPublished($published)
{
    $this->published = $published;

    return $this;
}

/**
 * Get published
 *
 * @return boolean
 */
public function getPublished()
{
    return $this->published;
}

/**
 * Set agentname
 *
 * @param string $agentname
 *
 * @return RDV
 */
public function setAgentname($agentname)
{
    $this->agentname = $agentname;

    return $this;
}

/**
 * Get agentname
 *
 * @return string
 */
public function getAgentname()
{
    return $this->agentname;
}

/**
 * Set adresse
 *
 * @param string $adresse
 *
 * @return RDV
 */
public function setAdresse($adresse)
{
    $this->adresse = $adresse;

    return $this;
}

/**
 * Get adresse
 *
 * @return string
 */
public function getAdresse()
{
    return $this->adresse;
}

/**
 * Set ville
 *
 * @param string $ville
 *
 * @return RDV
 */
public function setVille($ville)
{
    $this->ville = $ville;

    return $this;
}

/**
 * Get ville
 *
 * @return string
 */
public function getVille()
{
    return $this->ville;
}

/**
 * Set telfixe
 *
 * @param string $telfixe
 *
 * @return RDV
 */
public function setTelfixe($telfixe)
{
    $this->telfixe = $telfixe;

    return $this;
}

/**
 * Get telfixe
 *
 * @return string
 */
public function getTelfixe()
{
    return $this->telfixe;
}

/**
 * Set telpor
 *
 * @param string $telpor
 *
 * @return RDV
 */
public function setTelpor($telpor)
{
    $this->telpor = $telpor;

    return $this;
}

/**
 * Get telpor
 *
 * @return string
 */
public function getTelpor()
{
    return $this->telpor;
}

/**
 * Set tarif
 *
 * @param string $tarif
 *
 * @return RDV
 */
public function setTarif($tarif)
{
    $this->tarif = $tarif;

    return $this;
}

/**
 * Get tarif
 *
 * @return string
 */
public function getTarif()
{
    return $this->tarif;
}

/**
 * Set support
 *
 * @param string $support
 *
 * @return RDV
 */
public function setSupport($support)
{
    $this->support = $support;

    return $this;
}

/**
 * Get support
 *
 * @return string
 */
public function getSupport()
{
    return $this->support;
}

/**
 * Set horaire
 *
 * @param string $horaire
 *
 * @return RDV
 */
public function setHoraire($horaire)
{
    $this->horaire = $horaire;

    return $this;
}

/**
 * Get horaire
 *
 * @return string
 */
public function getHoraire()
{
    return $this->horaire;
}

/**
 * Set comname
 *
 * @param string $comname
 *
 * @return RDV
 */
public function setComname($comname)
{
    $this->comname = $comname;

    return $this;
}

/**
 * Get comname
 *
 * @return string
 */
public function getComname()
{
    return $this->comname;
}


/**
 * Set qualif
 *
 * @param string $qualif
 *
 * @return RDV
 */
public function setQualif($qualif)
{
    $this->qualif = $qualif;

    return $this;
}

/**
 * Get qualif
 *
 * @return string
 */
public function getQualif()
{
    return $this->qualif;
}
}

感谢您的帮助

2 个答案:

答案 0 :(得分:0)

它应该是实体字段的名称,而不是行

中指定的数据库列的名称
->where('company_events.event_datetime BETWEEN :startDate and :endDate')

所以检查,也许它应该像

->where('company_events.eventDatetime BETWEEN :startDate and :endDate')

假设您使用symfony编码样式标准在EventEntity字段名称上使用驼峰大小写。

=============================

更新

=============================

现在,当您发布实体时,很明显它不是您尝试通过存储库从数据库中获取的实体。

$companyEvents = $this->entityManager->getRepository('CMRBundle:EventEntity')
        ->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();

这里你的实体经理正在检索&#34; EventEntity&#34;来自存储库的实例,名称为&#34; CMRBundle:EventEntity&#34;,但是对于我们,您展示了&#34; RDV&#34;和&#34; CMRBundle \ Repository \ RDVRepository&#34;它属于哪个。据我所知,从你所展示的范围的一部分 - 当一些日历事件被提出时,你想要获得所有&#34;事件实体&#34;来自数据库,它们在您传递给侦听器的那些事件对象中设置的字段值的范围内。但目前还不清楚你所展示的那些RDV对象是否代表那些&#34;事件实体&#34;你想从数据库中获取。现在它看起来像和#34; CMRBundle:EventEntity&#34;只是看起来像你忘记改变的一些示例代码。所以,请尝试更仔细地描述我们的任务及其背景,并判断我的假设是对还是错。

答案 1 :(得分:0)

我的实体中有一个公共函数getDaterdv:

(我已将实体更改为)RDV:

<?php

namespace CMRBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * RDV
 *
 * @ORM\Table(name="r_d_v")
 * @ORM\Entity(repositoryClass="CMRBundle\Repository\RDVRepository")
 */
class RDV
{
 /**
 * @var int
 *
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
private $id;

/**
 * @var \DateTime
 *
 * @ORM\Column(name="datecrea", type="datetime")
 */
private $datecrea;

/**
  * @ORM\Column(name="published", type="boolean")
  */
private $published = true;

/**
 * @var \DateTime
 *
 * @ORM\Column(name="daterdv", type="datetime")
 */
private $daterdv;

/**
 * @var string
 *
 * @ORM\Column(name="title", type="string", length=255)
 */
private $title;


/**
 * @var string
 *
 * @ORM\Column(name="agentname", type="string", length=255)
 */
private $agentname;


/**
 * @var string
 *
 * @ORM\Column(name="qualif", type="string", length=255)
 */
private $qualif;

/**
 * @var int
 *
 * @ORM\Column(name="agentid", type="integer")
 */
private $agentid;

/**
 * @var string
 *
 * @ORM\Column(name="company", type="string", length=255)
 */
private $company;

/**
 * @var string
 *
 * @ORM\Column(name="comname", type="string", length=255)
 */
private $comname;

/**
 * @var text
 *
 * @ORM\Column(name="content", type="text")
 */
private $content;

/**
 * @var text
 *
 * @ORM\Column(name="adresse", type="text")
 */
private $adresse;

/**
 * @var text
 *
 * @ORM\Column(name="ville", type="text")
 */
private $ville;

/**
 * @var text
 *
 * @ORM\Column(name="telfixe", type="text")
 */
private $telfixe;

/**
 * @var text
 *
 * @ORM\Column(name="telpor", type="text")
 */
private $telpor;

/**
 * @var text
 *
 * @ORM\Column(name="tarif", type="text")
 */
private $tarif;

/**
 * @var text
 *
 * @ORM\Column(name="support", type="text")
 */
private $support;

public function __construct()
{
$this->datecrea = new \Datetime();
$this->daterdv = new \DateTime();
}

/**
 * Get id
 *
 * @return int
 */
public function getId()
{
    return $this->id;
}

/**
 * Set datecrea
 *
 * @param \DateTime $datecrea
 *
 * @return RDV
 */
public function setDatecrea($datecrea)
{
    $this->datecrea = $datecrea;

    return $this;
}

/**
 * Get datecrea
 *
 * @return \DateTime
 */
public function getDatecrea()
{
    return $this->datecrea;
}

/**
 * Set daterdv
 *
 * @param \DateTime $daterdv
 *
 * @return RDV
 */
public function setDaterdv($daterdv)
{
    $this->daterdv = $daterdv;

    return $this;
}

/**
 * Get daterdv
 *
 * @return \DateTime
 */
public function getDaterdv()
{
    return $this->daterdv;
}

/**
 * Set title
 *
 * @param string $title
 *
 * @return RDV
 */
public function setTitle($title)
{
    $this->title = $title;

    return $this;
}

/**
 * Get title
 *
 * @return string
 */
public function getTitle()
{
    return $this->title;
}

/**
 * Set agentid
 *
 * @param integer $agentid
 *
 * @return RDV
 */
public function setAgentid($agentid)
{
    $this->agentid = $agentid;

    return $this;
}

/**
 * Get agentid
 *
 * @return int
 */
public function getAgentid()
{
    return $this->agentid;
}

/**
 * Set company
 *
 * @param string $company
 *
 * @return RDV
 */
public function setCompany($company)
{
    $this->company = $company;

    return $this;
}

/**
 * Get company
 *
 * @return string
 */
public function getCompany()
{
    return $this->company;
}


/**
 * Set content
 *
 * @param string $content
 *
 * @return RDV
 */
public function setContent($content)
{
    $this->content = $content;

    return $this;
}

/**
 * Get content
 *
 * @return string
 */
public function getContent()
{
    return $this->content;
}

/**
 * Set published
 *
 * @param boolean $published
 *
 * @return RDV
 */
public function setPublished($published)
{
    $this->published = $published;

    return $this;
}

/**
 * Get published
 *
 * @return boolean
 */
public function getPublished()
{
    return $this->published;
}

/**
 * Set agentname
 *
 * @param string $agentname
 *
 * @return RDV
 */
public function setAgentname($agentname)
{
    $this->agentname = $agentname;

    return $this;
}

/**
 * Get agentname
 *
 * @return string
 */
public function getAgentname()
{
    return $this->agentname;
}

/**
 * Set adresse
 *
 * @param string $adresse
 *
 * @return RDV
 */
public function setAdresse($adresse)
{
    $this->adresse = $adresse;

    return $this;
}

/**
 * Get adresse
 *
 * @return string
 */
public function getAdresse()
{
    return $this->adresse;
}

/**
 * Set ville
 *
 * @param string $ville
 *
 * @return RDV
 */
public function setVille($ville)
{
    $this->ville = $ville;

    return $this;
}

/**
 * Get ville
 *
 * @return string
 */
public function getVille()
{
    return $this->ville;
}

/**
 * Set telfixe
 *
 * @param string $telfixe
 *
 * @return RDV
 */
public function setTelfixe($telfixe)
{
    $this->telfixe = $telfixe;

    return $this;
}

/**
 * Get telfixe
 *
 * @return string
 */
public function getTelfixe()
{
    return $this->telfixe;
}

/**
 * Set telpor
 *
 * @param string $telpor
 *
 * @return RDV
 */
public function setTelpor($telpor)
{
    $this->telpor = $telpor;

    return $this;
}

/**
 * Get telpor
 *
 * @return string
 */
public function getTelpor()
{
    return $this->telpor;
}

/**
 * Set tarif
 *
 * @param string $tarif
 *
 * @return RDV
 */
public function setTarif($tarif)
{
    $this->tarif = $tarif;

    return $this;
}

/**
 * Get tarif
 *
 * @return string
 */
public function getTarif()
{
    return $this->tarif;
}

/**
 * Set support
 *
 * @param string $support
 *
 * @return RDV
 */
public function setSupport($support)
{
    $this->support = $support;

    return $this;
}

/**
 * Get support
 *
 * @return string
 */
public function getSupport()
{
    return $this->support;
}

/**
 * Set horaire
 *
 * @param string $horaire
 *
 * @return RDV
 */
public function setHoraire($horaire)
{
    $this->horaire = $horaire;

    return $this;
}

/**
 * Get horaire
 *
 * @return string
 */
public function getHoraire()
{
    return $this->horaire;
}

/**
 * Set comname
 *
 * @param string $comname
 *
 * @return RDV
 */
public function setComname($comname)
{
    $this->comname = $comname;

    return $this;
}

/**
 * Get comname
 *
 * @return string
 */
public function getComname()
{
    return $this->comname;
}


/**
 * Set qualif
 *
 * @param string $qualif
 *
 * @return RDV
 */
public function setQualif($qualif)
{
    $this->qualif = $qualif;

    return $this;
}

/**
 * Get qualif
 *
 * @return string
 */
public function getQualif()
{
    return $this->qualif;
}
}