Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Symfony 6 php 8 Entity Form

I’m trying to create a form with Symfony 6 (without database behind).

I create an Entity like this :

<?php

namespace App\Entity;

class MyObject
{
    private string $name;

    public function getName(): ?string
    {
        return $this->$name;
    }

    public function setName($name): self
    {
        $this->$name = $name;

        return $this;
    }
}

?>

I created the MyObjectFormType with symfony console make:entity command.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

After that when I tried to show the form into my twig page, I’ve got an error Warning: Undefined variable $name.
I saw that in older version of php (and symfony) this annotation was used:

/**
 * @Var
 */

Does it exist on php 8 (by attributes)?

>Solution :

You have an error, it’s not:

$this->$name

but:

$this->name
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading