Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 条令2中多个实体的标签_Php_Symfony_Doctrine Orm - Fatal编程技术网

Php 条令2中多个实体的标签

Php 条令2中多个实体的标签,php,symfony,doctrine-orm,Php,Symfony,Doctrine Orm,我正试图创建一个简单的带有条令的标记系统,但我不确定如何构建实体关系。一个可以有多个标记的用户可能是一个简单的多个关联,但是当我有两个或多个可以标记的实体时会发生什么呢 我有三个实体:用户、组和应用程序。所有三个实体都可以标记。如何将这三者与标记实体联系起来?您应该在用户、组和应用程序实体中映射标记实体,如果您使用的是注释,则上述每个实体中的代码应该类似于以下内容: /** * @ORM\Table(name="class_name") * @ORM\Entity */ class Cla

我正试图创建一个简单的带有条令的标记系统,但我不确定如何构建实体关系。一个可以有多个标记的用户可能是一个简单的多个关联,但是当我有两个或多个可以标记的实体时会发生什么呢


我有三个实体:用户、组和应用程序。所有三个实体都可以标记。如何将这三者与标记实体联系起来?

您应该在用户、组和应用程序实体中映射标记实体,如果您使用的是注释,则上述每个实体中的代码应该类似于以下内容:

/**
 * @ORM\Table(name="class_name")
 * @ORM\Entity
 */
class ClassName {
    // Definition of other attributes skipped

    /**
     * @ORM\ManyToMany(targetEntity="Tag")
     */
    private $tags;

    public function __construct(){
         $this->tags = new ArrayCollection();
    }

    // Definition of other methods skipped

    public function getTags(){
        return $this->tags;
    }

    public function setTags($tags){
        $this->tags = $tags;
    }

    public function addTag(Tag $tag){
        $this->tags->add($tag);
    }

    public function removeTag(Tag $tag){
        $this->tags->remove($tag);
    }
}

您应该在用户、组和应用程序实体中映射标记实体,如果您使用的是注释,则上述每个实体中的代码应该类似于以下内容:

/**
 * @ORM\Table(name="class_name")
 * @ORM\Entity
 */
class ClassName {
    // Definition of other attributes skipped

    /**
     * @ORM\ManyToMany(targetEntity="Tag")
     */
    private $tags;

    public function __construct(){
         $this->tags = new ArrayCollection();
    }

    // Definition of other methods skipped

    public function getTags(){
        return $this->tags;
    }

    public function setTags($tags){
        $this->tags = $tags;
    }

    public function addTag(Tag $tag){
        $this->tags->add($tag);
    }

    public function removeTag(Tag $tag){
        $this->tags->remove($tag);
    }
}

您应该在用户、组和应用程序实体中映射标记实体,如果您使用的是注释,则上述每个实体中的代码应该类似于以下内容:

/**
 * @ORM\Table(name="class_name")
 * @ORM\Entity
 */
class ClassName {
    // Definition of other attributes skipped

    /**
     * @ORM\ManyToMany(targetEntity="Tag")
     */
    private $tags;

    public function __construct(){
         $this->tags = new ArrayCollection();
    }

    // Definition of other methods skipped

    public function getTags(){
        return $this->tags;
    }

    public function setTags($tags){
        $this->tags = $tags;
    }

    public function addTag(Tag $tag){
        $this->tags->add($tag);
    }

    public function removeTag(Tag $tag){
        $this->tags->remove($tag);
    }
}

您应该在用户、组和应用程序实体中映射标记实体,如果您使用的是注释,则上述每个实体中的代码应该类似于以下内容:

/**
 * @ORM\Table(name="class_name")
 * @ORM\Entity
 */
class ClassName {
    // Definition of other attributes skipped

    /**
     * @ORM\ManyToMany(targetEntity="Tag")
     */
    private $tags;

    public function __construct(){
         $this->tags = new ArrayCollection();
    }

    // Definition of other methods skipped

    public function getTags(){
        return $this->tags;
    }

    public function setTags($tags){
        $this->tags = $tags;
    }

    public function addTag(Tag $tag){
        $this->tags->add($tag);
    }

    public function removeTag(Tag $tag){
        $this->tags->remove($tag);
    }
}

地图的另一端呢?标记实体将有一个包含所有用户、组等的列表?@vinnylinux如果您需要另一端,则实现它。这完全取决于你需要什么。映射的另一端呢?标记实体将有一个包含所有用户、组等的列表?@vinnylinux如果您需要另一端,则实现它。这完全取决于你需要什么。映射的另一端呢?标记实体将有一个包含所有用户、组等的列表?@vinnylinux如果您需要另一端,则实现它。这完全取决于你需要什么。映射的另一端呢?标记实体将有一个包含所有用户、组等的列表?@vinnylinux如果您需要另一端,则实现它。这完全取决于你需要什么。