Created
January 12, 2017 17:06
-
-
Save eS-IT/66c6242fb406417a0b6e10c3a11564c5 to your computer and use it in GitHub Desktop.
Contao 4: Entity-Grundlagen - AcmeElement.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class AcmeElement extends \ContentElement | |
| { | |
| /** | |
| * Template | |
| * @var string | |
| */ | |
| protected $strTemplate = 'ce_esit_default'; | |
| /** | |
| * Generate the content element | |
| */ | |
| protected function compile() | |
| { | |
| if (TL_MODE == 'BE') { | |
| $this->strTemplate = 'be_wildcard'; | |
| $this->Template = new \BackendTemplate($this->strTemplate); | |
| $this->Template->wildcard = "### AcmeElement ###"; | |
| } else { | |
| // Get entity_manager | |
| $entityManager = \Contao\System::getContainer()->get('doctrine.orm.default_entity_manager'); | |
| // Postleitzahl anlegen | |
| $plz = new \Acme\TestBundle\Entity\TlAcmeArea(); | |
| $plz->setTstamp(time()); | |
| $plz->setPostal(59368); | |
| $plz->setCity('Werne'); | |
| $plz->setCountry('Nordrhein-Westfalen'); | |
| $entityManager->persist($plz); | |
| $entityManager->flush(); | |
| // Postleitzahl auslesen | |
| $plz = $entityManager->find('TlAcmeArea', 1); | |
| $this->Template->plz = $plz; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment