小编bed*_*mon的帖子

Doctrine2实体的动态表名

我正在尝试为我的一些实体添加动态表名.

我读了这篇文章[Doctrine 2中的动态表/实体名称] [1] [1]:Doctrine 2中的动态表/实体名称, 以及关于doctrine listener [doctrine listener] [2] [2]的这一个:http:// doctrine-orm.readthedocs.org/en/latest/reference/events.html

所以这是我尝试这样做的方式:

我在其表名中创建了一个带通配符的实体:

<?php

namespace DD\MyBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * SiteElec
 *
 * @ORM\Table(name="site_x_elec")
 * @ORM\Entity
 * @ORM\HasLifecycleCallbacks
 * @ORM\EntityListeners({"DD\MyBundle\Entity\Listener\SiteElecListener"})
 */
class SiteElec
{
    I skip properties with getters and setters

}
Run Code Online (Sandbox Code Playgroud)

接下来我为这个实体做了一个监听器:

<?php

namespace DD\MyBundle\Entity\Listener;

use DD\UserBundle\Entit\User;
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;

/**
 * Listener pour l'entité siteElec.
 */
class SiteElecListener {


private $_tableName = null;
protected $token_storage;
protected $user;

public function getTableName() { …
Run Code Online (Sandbox Code Playgroud)

php mysql symfony doctrine-orm

7
推荐指数
1
解决办法
2400
查看次数

标签 统计

doctrine-orm ×1

mysql ×1

php ×1

symfony ×1