我首先创建了数据库,然后从中生成了实体。之后,我使用以下方法在实体中生成了 getter 和 setter:
php app/console doctrine:generate:entities DigitalManager
后来我决定在实体之间创建关联(一对多),所以我在我的实体中添加了相应的命令,我得到的是:
当事人实体:
<?php
namespace DigitalManager\Bundle\ERPBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Party
*
* @ORM\Table(name="party")
* @ORM\Entity
*/
class Party
{
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=45, nullable=true)
*/
private $name;
/**
* @ORM\ManyToOne(targetEntity="Account", inversedBy="parties")
* @ORM\JoinColumn(name="account_id", referencedColumnName="aid")
*/
public $account;
/**
* @var string
*
* @ORM\Column(name="address", type="string", length=45, nullable=true)
*/
private $address;
/**
* @var string
*
* @ORM\Column(name="phone_fax", type="string", length=45, nullable=true)
*/
private $phoneFax;
/**
* @var string
*
* @ORM\Column(name="fax", type="string", length=45, nullable=true)
*/
private $fax;
/**
* @var string
*
* @ORM\Column(name="email", type="string", length=45, nullable=true)
*/
private $email;
/**
* @var string
*
* @ORM\Column(name="mobile", type="string", length=45, nullable=true)
*/
private $mobile;
/**
* @var string
*
* @ORM\Column(name="country", type="string", length=45, nullable=true)
*/
private $country;
/**
* @var string
*
* @ORM\Column(name="city", type="string", length=45, nullable=true)
*/
private $city;
/**
* @var string
*
* @ORM\Column(name="phone_res", type="string", length=45, nullable=true)
*/
private $phoneRes;
/**
* @var string
*
* @ORM\Column(name="remarks", type="string", length=45, nullable=true)
*/
private $remarks;
/**
* @var boolean
*
* @ORM\Column(name="active", type="boolean", nullable=true)
*/
private $active;
/**
* @var integer
*
* @ORM\Column(name="limit", type="integer", nullable=true)
*/
private $limit;
/**
* @var integer
*
* @ORM\Column(name="term", type="integer", nullable=true)
*/
private $term;
/**
* @var string
*
* @ORM\Column(name="officer_id", type="string", length=45, nullable=true)
*/
private $officerId;
/**
* @var \DateTime
*
* @ORM\Column(name="date", type="datetime", nullable=true)
*/
private $date;
/**
* @var string
*
* @ORM\Column(name="cnic", type="string", length=45, nullable=true)
*/
private $cnic;
/**
* @var string
*
* @ORM\Column(name="ntn", type="string", length=45, nullable=true)
*/
private $ntn;
/**
* @var boolean
*
* @ORM\Column(name="L_O", type="boolean", nullable=true)
*/
private $lO;
/**
* @var string
*
* @ORM\Column(name="type", type="string", length=45, nullable=true)
*/
private $type;
/**
* @var integer
*
* @ORM\Column(name="acc_id", type="integer", nullable=true)
*/
private $accId;
/**
* @var integer
*
* @ORM\Column(name="party_id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $partyId;
/**
* Set name
*
* @param string $name
* @return Party
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set address
*
* @param string $address
* @return Party
*/
public function setAddress($address)
{
$this->address = $address;
return $this;
}
/**
* Get address
*
* @return string
*/
public function getAddress()
{
return $this->address;
}
/**
* Set phoneFax
*
* @param string $phoneFax
* @return Party
*/
public function setPhoneFax($phoneFax)
{
$this->phoneFax = $phoneFax;
return $this;
}
/**
* Get phoneFax
*
* @return string
*/
public function getPhoneFax()
{
return $this->phoneFax;
}
/**
* Set fax
*
* @param string $fax
* @return Party
*/
public function setFax($fax)
{
$this->fax = $fax;
return $this;
}
/**
* Get fax
*
* @return string
*/
public function getFax()
{
return $this->fax;
}
/**
* Set email
*
* @param string $email
* @return Party
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Get email
*
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Set mobile
*
* @param string $mobile
* @return Party
*/
public function setMobile($mobile)
{
$this->mobile = $mobile;
return $this;
}
/**
* Get mobile
*
* @return string
*/
public function getMobile()
{
return $this->mobile;
}
/**
* Set country
*
* @param string $country
* @return Party
*/
public function setCountry($country)
{
$this->country = $country;
return $this;
}
/**
* Get country
*
* @return string
*/
public function getCountry()
{
return $this->country;
}
/**
* Set city
*
* @param string $city
* @return Party
*/
public function setCity($city)
{
$this->city = $city;
return $this;
}
/**
* Get city
*
* @return string
*/
public function getCity()
{
return $this->city;
}
/**
* Set phoneRes
*
* @param string $phoneRes
* @return Party
*/
public function setPhoneRes($phoneRes)
{
$this->phoneRes = $phoneRes;
return $this;
}
/**
* Get phoneRes
*
* @return string
*/
public function getPhoneRes()
{
return $this->phoneRes;
}
/**
* Set remarks
*
* @param string $remarks
* @return Party
*/
public function setRemarks($remarks)
{
$this->remarks = $remarks;
return $this;
}
/**
* Get remarks
*
* @return string
*/
public function getRemarks()
{
return $this->remarks;
}
/**
* Set active
*
* @param boolean $active
* @return Party
*/
public function setActive($active)
{
$this->active = $active;
return $this;
}
/**
* Get active
*
* @return boolean
*/
public function getActive()
{
return $this->active;
}
/**
* Set limit
*
* @param integer $limit
* @return Party
*/
public function setLimit($limit)
{
$this->limit = $limit;
return $this;
}
/**
* Get limit
*
* @return integer
*/
public function getLimit()
{
return $this->limit;
}
/**
* Set term
*
* @param integer $term
* @return Party
*/
public function setTerm($term)
{
$this->term = $term;
return $this;
}
/**
* Get term
*
* @return integer
*/
public function getTerm()
{
return $this->term;
}
/**
* Set officerId
*
* @param string $officerId
* @return Party
*/
public function setOfficerId($officerId)
{
$this->officerId = $officerId;
return $this;
}
/**
* Get officerId
*
* @return string
*/
public function getOfficerId()
{
return $this->officerId;
}
/**
* Set date
*
* @param \DateTime $date
* @return Party
*/
public function setDate($date)
{
$this->date = $date;
return $this;
}
/**
* Get date
*
* @return \DateTime
*/
public function getDate()
{
return $this->date;
}
/**
* Set cnic
*
* @param string $cnic
* @return Party
*/
public function setCnic($cnic)
{
$this->cnic = $cnic;
return $this;
}
/**
* Get cnic
*
* @return string
*/
public function getCnic()
{
return $this->cnic;
}
/**
* Set ntn
*
* @param string $ntn
* @return Party
*/
public function setNtn($ntn)
{
$this->ntn = $ntn;
return $this;
}
/**
* Get ntn
*
* @return string
*/
public function getNtn()
{
return $this->ntn;
}
/**
* Set lO
*
* @param boolean $lO
* @return Party
*/
public function setLO($lO)
{
$this->lO = $lO;
return $this;
}
/**
* Get lO
*
* @return boolean
*/
public function getLO()
{
return $this->lO;
}
/**
* Set type
*
* @param string $type
* @return Party
*/
public function setType($type)
{
$this->type = $type;
return $this;
}
/**
* Get type
*
* @return string
*/
public function getType()
{
return $this->type;
}
/**
* Set accId
*
* @param integer $accId
* @return Party
*/
public function setAccId($accId)
{
$this->accId = $accId;
return $this;
}
/**
* Get accId
*
* @return integer
*/
public function getAccId()
{
return $this->accId;
}
/**
* Get partyId
*
* @return integer
*/
public function getPartyId()
{
return $this->partyId;
}
}
账户实体
<?php
namespace DigitalManager\Bundle\ERPBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* Account
*
* @ORM\Table(name="account")
* @ORM\Entity
*/
class Account
{
public function __construct()
{
parent::__construct();
// The line below must be here as a single category is to be mapped to many products, so an ArrayCollection is required instead of Array.
$this->parties = new ArrayCollection();
}
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=45, nullable=true)
*/
private $name;
// The metadata above the $products property of the Category object is less important, and simply tells
// Doctrine to look at the Product.category property to figure out how the relationship is mapped.
/**
* @ORM\OneToMany(targetEntity="Party", mappedBy="account")
*/
protected $parties;
/**
* @var string
*
* @ORM\Column(name="address", type="string", length=200, nullable=true)
*/
private $address;
/**
* @var string
*
* @ORM\Column(name="level1", type="string", length=45, nullable=true)
*/
private $level1;
/**
* @var string
*
* @ORM\Column(name="level2", type="string", length=45, nullable=true)
*/
private $level2;
/**
* @var string
*
* @ORM\Column(name="level3", type="string", length=45, nullable=true)
*/
private $level3;
/**
* @var string
*
* @ORM\Column(name="contact", type="string", length=45, nullable=true)
*/
private $contact;
/**
* @var integer
*
* @ORM\Column(name="aid", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $aid;
/**
* Set name
*
* @param string $name
* @return Account
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set address
*
* @param string $address
* @return Account
*/
public function setAddress($address)
{
$this->address = $address;
return $this;
}
/**
* Get address
*
* @return string
*/
public function getAddress()
{
return $this->address;
}
/**
* Set level1
*
* @param string $level1
* @return Account
*/
public function setLevel1($level1)
{
$this->level1 = $level1;
return $this;
}
/**
* Get level1
*
* @return string
*/
public function getLevel1()
{
return $this->level1;
}
/**
* Set level2
*
* @param string $level2
* @return Account
*/
public function setLevel2($level2)
{
$this->level2 = $level2;
return $this;
}
/**
* Get level2
*
* @return string
*/
public function getLevel2()
{
return $this->level2;
}
/**
* Set level3
*
* @param string $level3
* @return Account
*/
public function setLevel3($level3)
{
$this->level3 = $level3;
return $this;
}
/**
* Get level3
*
* @return string
*/
public function getLevel3()
{
return $this->level3;
}
/**
* Set contact
*
* @param string $contact
* @return Account
*/
public function setContact($contact)
{
$this->contact = $contact;
return $this;
}
/**
* Get contact
*
* @return string
*/
public function getContact()
{
return $this->contact;
}
/**
* Get aid
*
* @return integer
*/
public function getAid()
{
return $this->aid;
}
}
添加这些关联命令后,我尝试使用以下方法为这些命令生成 getter 和 setter:
php 应用程序/控制台原则:生成:实体 DigitalManager
但它似乎没有为这些关联属性生成 getter 和 setter。我通过 Symfony2 文档查找了语法,创建关联也是一样的。谁能告诉我这里出了什么问题,为什么它不生成getter和setter,尽管属性在那里?