Note that there are some explanatory texts on larger screens.

plurals
  1. POExtend function with Doctrine ORM Annotation
    primarykey
    data
    text
    <p>I've got the following situation: a (Doctrine Entity) ContentCategory that is extending the DataObject class. The DataObject class has the following function, onPrePersist:</p> <pre><code>/** * @ORM\HasLifecycleCallbacks */ class DataObject implements InputFilterAwareInterface { ... /** @ORM\PrePersist */ public function onPrePersist() { //using Doctrine DateTime here $this-&gt;creation_date = new \DateTime('now'); } </code></pre> <p>The ContentCategory class needs this function aswell. When I put this function in the ContentCategory class it works just fine. Is there a way whereby, the ContentCategory class can use the same function, onPrePersist() without defining it in the class itsself?</p> <pre><code>* @ORM\HasLifecycleCallbacks() */ class ContentCategory extends DataObject implements InputFilterAwareInterface { ... } </code></pre> <p>The reason to give objects the onPrePersist function, is to set a DateTime when this object is created or any other object / entity that is extending the DataObject class.</p> <p>--&lt; Edited >--</p> <p>I've currently added a construct method to the ContentCategory like this:</p> <pre><code>public function __construct() { parent::onPrePersist(); } </code></pre> <p>In this way Doctrine executes the function onPersist when a new Entity is created. The other case is when an enttiy is being updated, with Doctrine. I'll like to set a Modified_date. In that case there will be a function like this, in the DataObject class.</p> <pre><code>/** * @ORM\HasLifecycleCallbacks */ class DataObject implements InputFilterAwareInterface { ... /** * @ORM\PreUpdate */ public function onUpdate() { $this-&gt;last_modified_date = new \DateTime('now'); } </code></pre> <p>The Doctrine ORM Annotation (PreUpdate) that have been added, will make sure that the function (above) will be excuted on an update statement for an object. The problem is, how to call those functions in an object which extends the DataObject</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload