Our objective for this tutorial is be able to create/manage the structure of your database table. Ec-cube uses doctrines which allows the user to easily manage the structure of the database. For Ec-cube, table manipulation mainly revolves around the 3 main files which are:
These 3 files are the minimum requirement in order to manage a database table in ec-cube.
Directory: EccubeRoot/src/Eccube/Resource/doctrine
You'll have to create a doctrine file to create define your database table. In this example let's create Eccube.Entity.Study.dcm.yml .
Eccube\Entity\Study: type: entity table: dtb_study repositoryClass: Eccube\Repository\StudyRepository id: id: type: integer nullable: false id: true column: study_id generator: strategy: AUTO options: unsigned: true fields: name: type: string length: 100 url: type: string nullable: true length: 200 create_date: type: datetime nullable: false update_date: type: datetime nullable: false lifecycleCallbacks: { }Directory: EccubeRoot/src/Eccube/Entity
Entities are php files that represents your table, these files usually contain setters and getters. For this example we'll create and use Study.php as our entity.
<?phpnamespace Eccube\Entity;use Doctrine\ORM\Mapping as ORM;/** * Study */class Study extends \Eccube\Entity\AbstractEntity{ /** * @return string */ public function __toString() { return $this->getName(); } /** * @var integer */ private $id; /** * @var string */ private $name; /** * @var string */ private $url; /** * @var \DateTime */ private $create_date; /** * @var \DateTime */ private $update_date; /** * Get id * * @return integer */ public function getId() { return $this->id; } /** * Set name * * @param string $name * @return Study */ public function setName($name) { $this->name = $name; return $this; } /** * Get name * * @return string */ public function getName() { return $this->name; } /** * Set name * * @param string $url * @return Study */ public function setUrl($url) { $this->url = $url; return $this; } /** * Get name * * @return string */ public function getUrl() { return $this->url; }}vendor/bin/doctrine orm:schema-tool:updatevendor/bin/doctrine orm:schema-tool:update --dump-sqlvendor/bin/doctrine orm:schema-tool:update --force