Атрибут объекта symfony не распознается при вызове в ветке

У меня есть форма, в которой я хочу настроить значения входных данных с помощью {{app.user.mail_2}}, но когда я это делаю, я получаю сообщение об ошибке:

Neither the property "mail_2" nor one of the methods "mail_2()", >"getmail_2()"/"ismail_2()"/"hasmail_2()" or "__call()" exist and have public >access in class "BAJ\BookingBundle\Entity\Drivers".

Я уже использовал его для названия, и он работает.

Вот мой код html.twig

      <div class = "clear"></div>
                <div id = "email-2" class = "form_element email-facultatif">
                    <div>2ème e-mail (facultatif)</div>
                    <input type = "email" class = "email-mobile-width" 
    name = "drivers[email_2]" placeholder = "EMAIL" value = "{{ app.user.mail_2 }}" 
    style = "border-bottom-right-radius: 0px;border-top-right-radius: 0px;width: 
    224px;"/>
                    <div class = "email-facultatif-block" id = "email-2-img"><img
                                src = "{{ asset('bundles/bajbooking/images/moin- 
    icon.png') }}" style = "width: 41px;"></div>
                </div>

и это моя сущность

 /**
   * Drivers
   *
   * @ORM\Table(name = "drivers")
   * @ORM\Entity(repositoryClass = "BAJ\BookingBundle\Repository\DriversRepository ")
   */
   class Drivers extends BaseUser
   {
/**
 * @ORM\Id
 * @ORM\Column(type = "integer")
 * @ORM\GeneratedValue(strategy = "AUTO")
 */
protected $id;

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

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

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

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

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

/**
 * @var string
 *
 * @ORM\Column(name = "date_of_brith", type = "string", nullable=true)
 */
private $dateOfBrith;

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

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

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

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

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

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

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

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

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

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

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

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

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

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


/**
 * @ORM\OneToMany(targetEntity = "Booking", mappedBy = "driver")
 */
private $bookings;

public function __construct() {
    $this->bookings = new ArrayCollection();
    parent::__construct();
}


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

/**
 * Set licenseDate
 *
 * @param \DateTime $licenseDate
 *
 * @return Drivers
 */
public function setLicenseDate($licenseDate)
{
    $this->licenseDate = $licenseDate;

    return $this;
}

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

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

    return $this;
}

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

/**
 * Set civility
 *
 * @param string $civility
 *
 * @return Drivers
 */
public function setCivility($civility)
{
    $this->civility = $civility;

    return $this;
}

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

/**
 * Set name
 *
 * @param string $name
 *
 * @return Drivers
 */
public function setName($name)
{
    $this->name = $name;

    return $this;
}

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

/**
 * Set firstName
 *
 * @param string $firstName
 *
 * @return Drivers
 */
public function setFirstName($firstName)
{
    $this->firstName = $firstName;

    return $this;
}

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

/**
 * Set dateOfBrith
 *
 * @param \DateTime $dateOfBrith
 *
 * @return Drivers
 */
public function setDateOfBrith($dateOfBrith)
{
    $this->dateOfBrith = $dateOfBrith;

    return $this;
}

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

/**
 * Add booking
 *
 * @param \BAJ\BookingBundle\Entity\Booking $booking
 *
 * @return Drivers
 */
public function addBooking(\BAJ\BookingBundle\Entity\Booking $booking)
{
    $this->bookings[] = $booking;

    return $this;
}

/**
 * Remove booking
 *
 * @param \BAJ\BookingBundle\Entity\Booking $booking
 */
public function removeBooking(\BAJ\BookingBundle\Entity\Booking $booking)
{
    $this->bookings->removeElement($booking);
}

/**
 * Get bookings
 *
 * @return \Doctrine\Common\Collections\Collection
 */
public function getBookings()
{
    return $this->bookings;
}

/**
 * Set phone
 *
 * @param string $phone
 *
 * @return Drivers
 */
public function setPhone($phone)
{
    $this->phone = $phone;

    return $this;
}

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

/**
 * Set address
 *
 * @param string $address
 *
 * @return Drivers
 */
public function setAddress($address)
{
    $this->address = $address;

    return $this;
}

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

/**
 * Set secondAddress
 *
 * @param string $secondAddress
 *
 * @return Drivers
 */
public function setSecondAddress($secondAddress)
{
    $this->second_address = $secondAddress;

    return $this;
}

/**
 * Get secondAddress
 *
 * @return string
 */
public function getSecondAddress()
{
    return $this->second_address;
}

/**
 * Set postalCode
 *
 * @param string $postalCode
 *
 * @return Drivers
 */
public function setPostalCode($postalCode)
{
    $this->postalCode = $postalCode;

    return $this;
}

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

/**
 * Set city
 *
 * @param string $city
 *
 * @return Drivers
 */
public function setCity($city)
{
    $this->city = $city;

    return $this;
}

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

/**
 * Set country
 *
 * @param string $country
 *
 * @return Drivers
 */
public function setCountry($country)
{
    $this->country = $country;

    return $this;
}

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

/**
 * Set mail2
 *
 * @param string $mail2
 *
 * @return Drivers
 */
public function setMail2($mail2)
{
    $this->mail_2 = $mail2;

    return $this;
}

/**
 * Get mail2
 *
 * @return string
 */
public function getMail2()
{
    return $this->mail_2;
}

/**
 * Set mail3
 *
 * @param string $mail3
 *
 * @return Drivers
 */
public function setMail3($mail3)
{
    $this->mail_3 = $mail3;

    return $this;
}

/**
 * Get mail3
 *
 * @return string
 */
public function getMail3()
{
    return $this->mail_3;
}

/**
 * Set mail4
 *
 * @param string $mail4
 *
 * @return Drivers
 */
public function setMail4($mail4)
{
    $this->mail_4 = $mail4;

    return $this;
}

/**
 * Get mail4
 *
 * @return string
 */
public function getMail4()
{
    return $this->mail_4;
}

/**
 * Set mail5
 *
 * @param string $mail5
 *
 * @return Drivers
 */
public function setMail5($mail5)
{
    $this->mail_5 = $mail5;

    return $this;
}

/**
 * Get mail5
 *
 * @return string
 */
public function getMail5()
{
    return $this->mail_5;
}

/**
 * Set phone2
 *
 * @param string $phone2
 *
 * @return Drivers
 */
public function setPhone2($phone2)
{
    $this->phone_2 = $phone2;

    return $this;
}

/**
 * Get phone2
 *
 * @return string
 */
public function getPhone2()
{
    return $this->phone_2;
}

/**
 * Set phone3
 *
 * @param string $phone3
 *
 * @return Drivers
 */
public function setPhone3($phone3)
{
    $this->phone_3 = $phone3;

    return $this;
}

/**
 * Get phone3
 *
 * @return string
 */
public function getPhone3()
{
    return $this->phone_3;
}

/**
 * Set phone4
 *
 * @param string $phone4
 *
 * @return Drivers
 */
public function setPhone4($phone4)
{
    $this->phone_4 = $phone4;

    return $this;
}

/**
 * Get phone4
 *
 * @return string
 */
public function getPhone4()
{
    return $this->phone_4;
}

/**
 * Set phone5
 *
 * @param string $phone5
 *
 * @return Drivers
 */
public function setPhone5($phone5)
{
    $this->phone_5 = $phone5;

    return $this;
}

/**
 * Get phone5
 *
 * @return string
 */
public function getPhone5()
{
    return $this->phone_5;
}
}

Опубликуйте свою сущность

fcpauldiaz 05.04.2018 01:10

я опубликовал это, ты можешь посмотреть

fedi oueslati 05.04.2018 11:45
Стоит ли изучать PHP в 2026-2027 годах?
Стоит ли изучать PHP в 2026-2027 годах?
Привет всем, сегодня я хочу высказать свои соображения по поводу вопроса, который я уже много раз получал в своем сообществе: "Стоит ли изучать PHP в...
Symfony Station Communiqué - 7 июля 2023 г
Symfony Station Communiqué - 7 июля 2023 г
Это коммюнике первоначально появилось на Symfony Station .
Symfony Station Communiqué - 17 февраля 2023 г
Symfony Station Communiqué - 17 февраля 2023 г
Это коммюнике первоначально появилось на Symfony Station , вашем источнике передовых новостей Symfony, PHP и кибербезопасности.
Управление ответами api для исключений на Symfony с помощью KernelEvents
Управление ответами api для исключений на Symfony с помощью KernelEvents
Много раз при создании api нам нужно возвращать клиентам разные ответы в зависимости от возникшего исключения.
0
2
64
2

Ответы 2

Я не думаю, что это та строка, которая вызывает ошибку. Ошибка говорит о том, что объект «Драйверы» не имеет свойства «mail_2», и вы вызываете «app.user», который является полностью аутентифицированным пользователем, вошедшим в систему.

Думаю, где-то еще на странице вам звонил driver.email_2.

Свойство mail_2 не имеет публичного доступа (что нормально), а метод getMail_2 () не существует в вашем классе.

{{ app.user.getMail2() }} или {{ app.user.mail2 }} должны работать.

Кроме того, это рекомендуетсянет, чтобы использовать символы подчеркивания для имен переменных и методов.

Другие вопросы по теме