0
我在symfony中新,我創建的附加小DB模式: Symfony的開捕致命錯誤:類的appbundle 實體電子郵件的對象不能轉換爲字符串
電子郵件類:
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Email
*
* @ORM\Table()
* @ORM\Entity(repositoryClass="AppBundle\Entity\EmailRepository")
*/
class Email extends Service
{
/**
* @var string
*
* @ORM\Column(name="emailAddress", type="string", length=255)
*/
private $emailAddress;
/**
* Set emailAddress
*
* @param string $emailAddress
*
* @return Email
*/
public function setEmailAddress($emailAddress)
{
$this->emailAddress = $emailAddress;
return $this;
}
/**
* Get emailAddress
*
* @return string
*/
public function getEmailAddress()
{
return $this->emailAddress;
}
}
,我的服務類:
<?php
namespace AppBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
* Service
*
* @ORM\Table()
* @ORM\Entity(repositoryClass="AppBundle\Entity\ServiceRepository")
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="type", type="string")
* @ORM\DiscriminatorMap({"newsletter" = "Newsletter", "email" = "Email", "service" = "Service"})
*
*/
class Service
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="serviceTitle", type="string", length=255)
*/
private $serviceTitle;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set serviceTitle
*
* @param string $serviceTitle
*
* @return Service
*/
public function setServiceTitle($serviceTitle)
{
$this->serviceTitle = $serviceTitle;
return $this;
}
/**
* Get serviceTitle
*
* @return string
*/
public function getServiceTitle()
{
return $this->serviceTitle;
}
/**
* @ORM\ManyToOne(targetEntity="Service", inversedBy="children")
*/
private $parent;
/**
* @ORM\OneToMany(targetEntity="Service", mappedBy="parent")
*/
private $children;
/**
* Constructor
*/
public function __construct()
{
$this->children = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Set parent
*
* @param \AppBundle\Entity\Service $parent
*
* @return Service
*/
public function setParent(\AppBundle\Entity\Service $parent = null)
{
$this->parent = $parent;
return $this;
}
/**
* Get parent
*
* @return \AppBundle\Entity\Service
*/
public function getParent()
{
return $this->parent;
}
/**
* Add child
*
* @param \AppBundle\Entity\Service $child
*
* @return Service
*/
public function addChild(\AppBundle\Entity\Service $child)
{
$this->children[] = $child;
return $this;
}
/**
* Remove child
*
* @param \AppBundle\Entity\Service $child
*/
public function removeChild(\AppBundle\Entity\Service $child)
{
$this->children->removeElement($child);
}
/**
* Get children
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getChildren()
{
return $this->children;
}
}
然後我生成電子郵件污物,這是工作完美,現在其實我是想增加對SERV兩個字段冰(SERVICE TITLE和父服務)
我做什麼,我剛打開電子郵件類型的表單,並增加了(服務名稱和家長服務)兩個字段:
<?php
namespace AppBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class EmailType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('emailAddress')
->add('serviceTitle')
->add('parent')
;
}
保存後
,當我創建新電子郵件服務的瀏覽器返回異常:
捕致命錯誤:Object類的appbundle \實體\的電子郵件不能被現在我只需要添加父ID在文本框中轉換成字符串
(輸入ŧ YPE文本),但實際上我想用(選擇莉莎),從該用戶可以創建新的服務的時候設置一個父服務,並且具有所有以前創建的服務
這樣的選擇列表
酷,現在我可以進入服務,與父(選擇列表) 選擇列表纔有價值= ID(服務ID)和文本(電子郵件地址) 我想顯示的文字(服務標題)而不是電子郵件地址,你能告訴我我該怎麼做? 感謝您的回答。 – Abid
只需更改返回$ this-> emailAddress;到任何你喜歡的東西;-) –
return $ this-> getServiceTitle(); –