Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I tried to do the same thing earlier. I had to find out it is not possible to use these two things together, you have to implement it for yourselfe.</p> <p>I did it this way: Text.php</p> <pre><code>use Gedmo\Mapping\Annotation as Gedmo; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Table(name="text") * @ORM\Entity * @Gedmo\Loggable */ class Text { /** @ORM\Id @ORM\GeneratedValue @ORM\Column(type="integer") */ private $id; /** @ORM\Column(name="class", type="string") */ private $class; /** @ORM\Column(name="field", type="string") */ private $field; /** @ORM\Column(name="key_id", type="integer") */ private $key_id; /** * @ORM\ManyToOne(targetEntity="Language") * @ORM\JoinColumns({ * @ORM\JoinColumn(name="lang_id", referencedColumnName="id") * }) */ private $lang; /** * @Gedmo\Versioned * @ORM\Column(name="text", type="text") */ private $text; ...getter setter... } </code></pre> <p>Language.php</p> <pre><code>use Doctrine\ORM\Mapping as ORM; /** * @ORM\Table(name="language") * @ORM\Entity */ class Language { /** @ORM\Id @ORM\GeneratedValue @ORM\Column(type="integer") */ private $id; /** @var @ORM\Column(name="language", type="string") */ private $language; ... getter setter .... </code></pre> <p>Now I wrote a service for managing these: TextManager.php</p> <pre><code>/** * @param $object * @param $field * @param $langKey * @return Text * * gets the existing text for the object * if it does not exist, it creates a new one */ public function setupText($object, $field, $langKey){ $lang = $this-&gt;langRepo-&gt;findOneBy(array("language" =&gt; $langKey)); $txt = $this-&gt;textRepo-&gt;findOneBy(array( 'class' =&gt; get_class($object), 'field' =&gt; $field, 'lang' =&gt; $lang, 'key_id' =&gt; $object-&gt;getId() )); if($txt != null){ return $txt; } $txt = new Text(); $txt-&gt;setClass(get_class($object)); $txt-&gt;setField($field); $txt-&gt;setKeyId($object-&gt;getId()); $txt-&gt;setLang($lang); return $txt; } /** * @param $object * @param $field * @param $langKey * @return mixed * gives you the text object or false if not found */ public function getText($object, $field, $langKey){ $lang = $this-&gt;langRepo-&gt;findOneBy(array("language" =&gt; $langKey)); $txt = $this-&gt;textRepo-&gt;findOneBy(array( 'class' =&gt; get_class($object), 'field' =&gt; $field, 'lang' =&gt; $lang, 'key_id' =&gt; $object-&gt;getId() )); if ($txt == null){ return false; } return $txt; } </code></pre> <p>In your controller you can now to things like that: to get an text object in ohter version</p> <pre><code>$logRepo = $em-&gt;getRepository('Gedmo\Loggable\Entity\LogEntry'); // we use default log entry class $text = $textManager-&gt;setupText($object, 'abouttext', 'de'); $logRepo-&gt;revert($text, 1); //1 is the version you would like to have $text-&gt;getText(); //version 1 text </code></pre> <p>to make a new text object</p> <pre><code>$text = $textManager-&gt;setupText($object, 'otherfield', 'fr'); $text-&gt;setText("your super text"); $em-&gt;persist($text); $em-&gt;flush(); </code></pre> <p>Hope it helps you, and if you have any question, dont mind asking.</p>
    singulars
    1. This table or related slice is empty.
    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.
    1. VO
      singulars
      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