ancarebeca / FullCalendarBundle

Symfony3 integration with the library FullCalendar.js
36 stars 38 forks source link

__construct() must be an instance of Doctrine\\ORM\\EntityManager #40

Closed ibrasdev closed 6 years ago

ibrasdev commented 6 years ago

Hello, I dont know why i cant run the calendar in good way this is my files please help me its been 2 weeks that i try to solve that :

LoadData :

`<?php

namespace CMRBundle\EventListener;

use AncaRebeca\FullCalendarBundle\Event\CalendarEvent; use AncaRebeca\FullCalendarBundle\Model\Event; use AncaRebeca\FullCalendarBundle\Model\FullCalendarEvent; use CMRBundle\Entity\Schedule; use Doctrine\ORM\EntityManager; class LoadDataListener { /**

Schedule :

`<?php

namespace CMRBundle\EventListener;

use Doctrine\ORM\Mapping as ORM;

/**

And this is the error i dont understand what im missing : {"error":"Catchable Fatal Error: Argument 1 passed to CMRBundle\\EventListener\\LoadDataListener::__construct() must be an instance of Doctrine\\ORM\\EntityManager, none given, called in C:\\wamp64\\www\\No\\var\\cache\\dev\\appDevDebugProjectContainer.php on line 492 and defined"}

Ive used the example available

PATATESUPREME commented 6 years ago

Hello @ibrasdev ,

Your class LoadDataListener looks like a service. If so you might have declared it in a service.yml. Then did you place the right service in the arguments of this service ?

ibrasdev commented 6 years ago

Yes ive declared the service in services.yml of CMRBundle : ` cmr.service.listener: class: CMRBundle\EventListener\LoadDataListener tags:

Thank you for helping

PATATESUPREME commented 6 years ago

Ok then to solve your error, you need to add to your service cmr.service.listener : arguments: ["@doctrine.orm.entity_manager"]

ibrasdev commented 6 years ago

Thank you very much its been 2 weeks that i try to solve this much love ! But i have an other problem : Error: Cannot instantiate abstract class AncaRebeca\FullCalendarBundle\Model\Event

its about : foreach ($schedules as $schedule) { $calendarEvent->addEvent(new Event($schedule->getTitle(), $schedule->getStart())); }

PATATESUPREME commented 6 years ago

Look at the step 3 of the installation, You need to create a custom Entity that extends the Event class.

ibrasdev commented 6 years ago

I already created the Schedule entity and ive created 2 events on db but still have same errors

PATATESUPREME commented 6 years ago

I see, instead of adding your custom event Schedule, you should :

  1. Extend the class event :
    
    use AncaRebeca\FullCalendarBundle\Model\Event;

class Schedule extends Event {

2. Add the new custom event :
```php
foreach ($schedules as $schedule) {
    $calendarEvent->addEvent($schedule);
}

Then this should be good.

ibrasdev commented 6 years ago

Ive added what you said, the error seem to be fixed but i got a new error :( Compile Error: Access level to CMRBundle\Entity\Schedule::$id must be protected My class Schedule must be empty ?

PATATESUPREME commented 6 years ago

Your class Schedule does'nt need to be empty. But if you open the class AncaRebeca\FullCalendarBundle\Model\Event, you will see some fields already existant.

There are many solutions to this issue :

Pick the one you need.

ibrasdev commented 6 years ago

Hello, I think that i turn around, i got this error : Error: Call to a member function format() on null

Its about : $event['start'] = $this->getStartDate()->format("Y-m-d\TH:i:sP");

This is my class Schedule : `class Schedule extends Event { /**

}`

Ive just put the id and ive delete it from Event : ` class Event implements EventInterface { /**

PATATESUPREME commented 6 years ago

You have two issues here :

  1. You are making the calendar bundle instable by deleting id of the Event class. My advice would be to restore Event as it was and then put protected on the Schedule $id. But that's not the reason of your issue.
  2. Then format is generally called on Datetime properties. Where is this function used ?
ibrasdev commented 6 years ago

The function is used on Event.php : $event['start'] = $this->getStartDate()->format("Y-m-d\TH:i:sP");

When i genetrate entities i only got the id field on the schedule table not all the fields from the Event

PATATESUPREME commented 6 years ago

Two ways again :

  1. Change your fields in Schedule : In the Event class their is already $title and $startDate, so change :
         private $start;

    to

         protected $startDate;
  2. Or instead of calling the event date, call the schedule date :
        $event['start'] = $this->getStart()->format("Y-m-d\TH:i:sP");
ibrasdev commented 6 years ago

Hello, Ive recreated Schedule Entity based on Event.php now i got all the fields on the db with protected.

I got this new error : {"error":"Could not convert database value \"\" to Doctrine Type array"}

ibrasdev commented 6 years ago

Ma patate tu est ou i need you xD

PATATESUPREME commented 6 years ago

Are the data in your DB important ?

  1. You could truncate the Schedule table
  2. Or set the wrong values with an empty array in the DB like a:0:{}
ibrasdev commented 6 years ago

Yes ive generated a new table with all the fields in the Event.php But when i try to load fixture i got this error : [Symfony\Component\Debug\Exception\ContextErrorException] Warning: Missing argument 1 for CMRBundle\Entity\Schedule::__construct(), c alled in C:\wamp64\www\No\src\CMRBundle\DataFixtures\ORM\LoadScheduleData.p hp on line 12 and defined

This is the LoadScheduleData.php: `public function load(ObjectManager $manager) { $schedule = new Schedule(); $schedule->setTitle('Yoga class'); $today = new \DateTime(); $schedule->setStartDate($today); $schedule->setEndDate($today); $manager->persist($schedule);

    $schedule = new Schedule();
    $schedule->setTitle('German class');
    $tomorrow = new \DateTime('tomorrow');
    $schedule->setStartDate($tomorrow);
    $schedule->setEndDate($tomorrow);
    $manager->persist($schedule);

    $manager->flush();
}`

its about : $schedule = new Schedule();

ibrasdev commented 6 years ago

Si if i have all the fields on the Schedule i must delete the extends Event ?

PATATESUPREME commented 6 years ago

No, but since you extends this class the __construct is diferent :


    /**
     * @param string $title
     * @param \DateTime $start
     */
    public function __construct($title, \DateTime $start)
    {
        $this->title = $title;
        $this->startDate = $start;
    }
ibrasdev commented 6 years ago

This is the same code that i have in Event; nothing changes still got the error on doctrine:fixtures:load and on the calendar page Error: Call to a member function format() on null

If the db is empty i got : [] on a blank page but if i add something in the db i got : {"error":"Could not convert database value \"\" to Doctrine Type array"}

PATATESUPREME commented 6 years ago

The construct needs additionnal parameters, so change your fixture :

$schedule = new Schedule();
$schedule->setTitle('Yoga class');
$today = new \DateTime();
$schedule->setStartDate($today);

to

$today = new \DateTime();
$schedule = new Schedule('Yoga class', $today);
ibrasdev commented 6 years ago

Merci patate.

I dont have more errors on the page but when i acces "full-calendar/load" i have an array with the correct informations in the DB ! Yeah :) But when i show the calendar there is no events !

PATATESUPREME commented 6 years ago

You're Welcome !

At least you made some progress.

ibrasdev commented 6 years ago

Yes Grace à toi :)

But why i dont get events on the calendar layout ?

PATATESUPREME commented 6 years ago

When you're on the calendar layout. What does the profiler says about your ajax requests ?

ibrasdev commented 6 years ago

The profiler shows :

POST | xhr | 404 | /full-calendar/load | 26ms | n/a

PATATESUPREME commented 6 years ago

Did you add the code below in your routing.yml ?

ancarebeca_fullcalendar:
    resource: "@FullCalendarBundle/Resources/config/routing.yml"
ibrasdev commented 6 years ago

Yes of course when i access app_dev.php/full-calendar/load i got the events from the table on an array, But in the layout cant get events and my ajax request still 404

PATATESUPREME commented 6 years ago

Try to clear the cache of the prod environnement.

ibrasdev commented 6 years ago

Ive clear the DEV&PROD cache but nothing changes, i got the same error and my ajax request still 404 :-( 1 2

2

PATATESUPREME commented 6 years ago

Is FOSJsRouting config properly ?

ibrasdev commented 6 years ago

Yeah ive already config it jsrouting-bundle version 1.6.1.

ibrasdev commented 6 years ago

There is a way to know that ive config well the jsrouting ?

PATATESUPREME commented 6 years ago

Sorry @ibrasdev, I'm out of time for today. I'll be back tomorrow.

ancarebeca commented 6 years ago

Thank you very much @PATATESUPREME 👍 for your collaboration on this issue. Looks like the original issue was solved, I am going to close this.