Skip to content

Instantly share code, notes, and snippets.

@eS-IT
Created January 12, 2017 17:06
Show Gist options
  • Select an option

  • Save eS-IT/66c6242fb406417a0b6e10c3a11564c5 to your computer and use it in GitHub Desktop.

Select an option

Save eS-IT/66c6242fb406417a0b6e10c3a11564c5 to your computer and use it in GitHub Desktop.
Contao 4: Entity-Grundlagen - AcmeElement.php
<?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