Skip to content

Instantly share code, notes, and snippets.

@Digi92
Created April 15, 2017 20:57
Show Gist options
  • Select an option

  • Save Digi92/568d1024ecab520554aed21b4578c972 to your computer and use it in GitHub Desktop.

Select an option

Save Digi92/568d1024ecab520554aed21b4578c972 to your computer and use it in GitHub Desktop.
Doctrine Beispiel zum Erstellen einer Base Entity Klasse so das alle anderen Klassen die diese Extenden die Felder auch in der Datenbank bekommen. Die Base Entity Klasse benötigt nur "@Orm\MappedSuperclass" als Annotation.
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Class BaseEntity
* @package AppBundle\Entity
* @ORM\MappedSuperclass
*/
class BaseEntity
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @var integer
*/
private $id;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
}
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Class ChildEntity
* @package AppBundle\Entity
* @ORM\Entity
* @ORM\Table(name="child_entity")
*/
class ChildEntity extends BaseEntity
{
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment