Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<?php tag missing in code during 13 "Managing the Lifecycle of Doctrine Objects" #8

Open
TrackLab opened this issue Jan 23, 2025 · 0 comments

Comments

@TrackLab
Copy link

During the Chapter "Managing the Lifecycle of Doctrine Objects", one is asked to create a Doctrine entity listener. With a block of code to copy.

The code block forgets to add a <?php tag in the beginning, resulting in the document being displayed as HTML Text over the website.
Without knowing about the needed tag, this is a weird behaviour without obvious solution.

The fixed code would be

<?php

namespace App\EntityListener;

use App\Entity\Conference;
use Doctrine\Persistence\Event\LifecycleEventArgs;
use Symfony\Component\String\Slugger\SluggerInterface;

class ConferenceEntityListener
{
    public function __construct(
        private SluggerInterface $slugger,
    ) {
    }

    public function prePersist(Conference $conference, LifecycleEventArgs $event)
    {
        $conference->computeSlug($this->slugger);
    }

    public function preUpdate(Conference $conference, LifecycleEventArgs $event)
    {
        $conference->computeSlug($this->slugger);
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant