Symfony实体属性在树枝中未能识别



我有一个形式,我想通过使用{{app.user.mail_2}}来设置输入的值,但是当我这样做时,我会收到错误:

均不是属性" mail_2",也不是一种方法" mail_2((",>" getMail_2(("/" ismail_2(("/" hasmail_2(("或" __call(("或" __call(("在" 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
   *
   * @ORMTable(name="drivers")
   * @ORMEntity(repositoryClass="BAJBookingBundleRepositoryDriversRepository ")
   */
   class Drivers extends BaseUser
   {
/**
 * @ORMId
 * @ORMColumn(type="integer")
 * @ORMGeneratedValue(strategy="AUTO")
 */
protected $id;
/**
 * @var string
 *
 * @ORMColumn(name="license_date", type="string", length=255, nullable=true)
 */
private $licenseDate;
/**
 * @var string
 *
 * @ORMColumn(name="title", type="string", length=255, nullable=true)
 */
private $title;
/**
 * @var string
 *
 * @ORMColumn(name="civility", type="string", length=255, nullable=true)
 */
private $civility;
/**
 * @var string
 *
 * @ORMColumn(name="name", type="string", length=255, nullable=true)
 */
private $name;
/**
 * @var string
 *
 * @ORMColumn(name="first_name", type="string", length=255, nullable=true)
 */
private $firstName;
/**
 * @var string
 *
 * @ORMColumn(name="date_of_brith", type="string", nullable=true)
 */
private $dateOfBrith;
/**
 * @var string
 *
 * @ORMColumn(name="phone", type="string", length=255, nullable=true)
 */
private $phone;
/**
 * @var string
 *
 * @ORMColumn(name="address", type="string", length=255, nullable=true)
 */
private $address;
/**
 * @var string
 *
 * @ORMColumn(name="second_address", type="string", length=255, nullable=true)
 */
private $second_address;
/**
 * @var string
 *
 * @ORMColumn(name="postal_code", type="string", length=255, nullable=true)
 */
private $postalCode;
/**
 * @var string
 *
 * @ORMColumn(name="city", type="string", length=255, nullable=true)
 */
private $city;
/**
 * @var string
 *
 * @ORMColumn(name="country", type="string", length=255, nullable=true)
 */
private $country;
/**
 * @var string
 *
 * @ORMColumn(name="mail_2", type="string", length=255, nullable=true)
 */
private $mail_2;
/**
 * @var string
 *
 * @ORMColumn(name="mail_3", type="string", length=255, nullable=true)
 */
private $mail_3;
/**
 * @var string
 *
 * @ORMColumn(name="mail_4", type="string", length=255, nullable=true)
 */
private $mail_4;
/**
 * @var string
 *
 * @ORMColumn(name="mail_5", type="string", length=255, nullable=true)
 */
private $mail_5;
/**
 * @var string
 *
 * @ORMColumn(name="phone_2", type="string", length=255, nullable=true)
 */
private $phone_2;
/**
 * @var string
 *
 * @ORMColumn(name="phone_3", type="string", length=255, nullable=true)
 */
private $phone_3;
/**
 * @var string
 *
 * @ORMColumn(name="phone_4", type="string", length=255, nullable=true)
 */
private $phone_4;
/**
 * @var string
 *
 * @ORMColumn(name="phone_5", type="string", length=255, nullable=true)
 */
private $phone_5;

/**
 * @ORMOneToMany(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 BAJBookingBundleEntityBooking $booking
 *
 * @return Drivers
 */
public function addBooking(BAJBookingBundleEntityBooking $booking)
{
    $this->bookings[] = $booking;
    return $this;
}
/**
 * Remove booking
 *
 * @param BAJBookingBundleEntityBooking $booking
 */
public function removeBooking(BAJBookingBundleEntityBooking $booking)
{
    $this->bookings->removeElement($booking);
}
/**
 * Get bookings
 *
 * @return DoctrineCommonCollectionsCollection
 */
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;
}
}

" mail_2"属性没有公共访问(这是正常(,而getMail_2((方法中不存在。

{{ app.user.getMail2() }}{{ app.user.mail2 }}应该起作用。

此外,建议不是使用下划线作为变量和方法名称。

我不认为这是抛出错误的行。该错误说实体"驱动程序"没有属性" mail_2",而您正在调用" app.user",该应用程序是完全认可的登录用户。

我认为您已调用driver.email_2的页面上的其他地方。

最新更新