douzhuo1858 2013-03-04 08:54
浏览 35
已采纳

学说属性映射

I just started working with symfony and doctrine. I have a simple entity which has one property is not tied with the database. This property should contain the contents of the xml file (I wanna make xml file, when doctrine add rows to the database).

/**
 * Layouts
 *
 * @ORM\Table(name="layouts")
 * @ORM\Entity
 * @ORM\HasLifecycleCallbacks()
 */
class Layouts
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="SEQUENCE")
     * @ORM\SequenceGenerator(sequenceName="layouts_id_seq", allocationSize=1, initialValue=1)
     */
    private $id;

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

    /**
     * ???????
     */
    private $template_body;
    ...
}

How to describe $template_body property? Without leaving the property description, I ran into a problem - the doctrine does not cause preUpdate method when I edit this property in the form.

  • 写回答

1条回答 默认 最新

  • douxian3828 2013-03-04 09:01
    关注

    You can do that my simply flagging a PreUpdate method in your class, which in turn begins working on your $template_body variable.

    Please change

    * @ORM\HasLifecycleCallbacks() 
    

    to

    * @ORM\HasLifecycleCallbacks 
    

    and create a function like so..

    /**
     * @PreUpdate
     */
    public function myUpdateFunction()
    {
       // Do stuff
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型