Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.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
Symfony和条令数据库_Symfony_Doctrine Orm - Fatal编程技术网

Symfony和条令数据库

Symfony和条令数据库,symfony,doctrine-orm,Symfony,Doctrine Orm,我正在从事一些新项目,该项目几乎使用Symfony framework完成,但我习惯于CodeIgnitor framework的问题,基本上作为Java开发人员/Android,在从事Web开发时,我对很多东西感到困惑,因此情况如下: 该网站有一个用户端和一个管理端(我在管理端工作),所以数据库中有这些表,我真的不明白为什么它们是这样构建的,但这不是问题所在 我想知道的是如何使用表单或任何其他方式在服务类别翻译中添加服务类别字段和相应的翻译 这是ServiceCategory实体 use D

我正在从事一些新项目,该项目几乎使用Symfony framework完成,但我习惯于CodeIgnitor framework的问题,基本上作为Java开发人员/Android,在从事Web开发时,我对很多东西感到困惑,因此情况如下: 该网站有一个用户端和一个管理端(我在管理端工作),所以数据库中有这些表,我真的不明白为什么它们是这样构建的,但这不是问题所在

我想知道的是如何使用表单或任何其他方式在服务类别翻译中添加服务类别字段和相应的翻译

这是ServiceCategory实体

use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Model as ORMBehaviors;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use JMS\Serializer\Annotation as Serializer;

/**
 * class ServiceCategory
 *
 * @ORM\Table(name="service_category")
 * @ORM\Entity
 *
 * @Serializer\ExclusionPolicy("all")
 */
class ServiceCategory
{

    use ORMBehaviors\Timestampable\Timestampable;
    use ORMBehaviors\SoftDeletable\SoftDeletable;
    use ORMBehaviors\Translatable\Translatable;

    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     *
     * @Serializer\Expose
     * @Serializer\Groups({"general-information", "service-offer"})
     */
    private $id;

    /**
     * @var ServiceGroup
     *
     * @ORM\OneToMany(targetEntity="ServiceGroup", mappedBy="serviceCategory")
     *
     * @Serializer\Expose
     * @Serializer\Groups({"service-offer"})
     */
    private $serviceGroup;

    /**
     * Constructor
     */
    public function __construct()
    {
        $this->serviceGroup = new ArrayCollection();
    }

    /**
     * {@inheritdoc}
     */
    public function __toString()
    {
        return $this->getName() ? $this->getName() : '';
    }

    /**
     * Get id
     *
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Get translated name
     *
     * @return string
     *
     * @Serializer\VirtualProperty
     * @Serializer\SerializedName("name")
     * @Serializer\Groups({"invoice-list", "service-offer"})
     */
    public function getName()
    {
        if($this->getTranslations()->get($this->getCurrentLocale()) == null){
            return 'sorry';
        }
        return $this->getTranslations()->get($this->getCurrentLocale())->getName();
    }

    /**
     * Add serviceGroup
     *
     * @param ServiceGroup $serviceGroup
     *
     * @return ServiceCategory
     */
    public function addServiceGroup(ServiceGroup $serviceGroup)
    {
        $this->serviceGroup[] = $serviceGroup;

        return $this;
    }

    /**
     * Remove serviceGroup
     *
     * @param ServiceGroup $serviceGroup
     */
    public function removeServiceGroup(ServiceGroup $serviceGroup)
    {
        $this->serviceGroup->removeElement($serviceGroup);
    }

    /**
     * Get serviceGroup
     *
     * @return Collection
     */
    public function getServiceGroup()
    {
        return $this->serviceGroup;
    }
}
这是ServiceCategoryTranslation实体

use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Model as ORMBehaviors;

/**
 * Class ServiceCategoryTranslation
 *
 * @package CoreBundle\Entity
 *
 * @ORM\Entity
 * @ORM\Table(name="service_category_translation")
 */
class ServiceCategoryTranslation
{
    use ORMBehaviors\Translatable\Translation;
    use ORMBehaviors\Timestampable\Timestampable;
    use ORMBehaviors\SoftDeletable\SoftDeletable;

    /**
     * @ORM\Column(type="string", length=255)
     */
    protected $name;

    /**
     * @return string
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * @param  string
     * @return null
     */
    public function setName($name)
    {
        $this->name = $name;
    }
    public function __toString() {
        return $this->name;
    }
}
我怎样才能做到这一点? 请不要带我去symfony或条令文件,我已经在那里丢了两天了,我的日程安排要迟到了


提前感谢

因为我假设您是服务类别(1)到服务类别翻译(多)之间存在一对多关联 将管理类别中的交易。这必须是一个双向关联,看看 您必须添加一个属性来管理实体和描述关联。我将使用注释来完成它

use Doctrine\Common\Collections\ArrayCollection;

class ServiceCategory
{
    /**
     * @OneToMany(targetEntity="ServiceCategoryTranslation", mappedBy="serviceCategory")
     **/
    private $translations;

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

    /**
     * @return ServiceCategoryTranslation[]
     */
    public function getStandort(){
        return $this->translations;
    }

    /**
     * @param ArrayCollection $translations
     * @return ServiceCategory
     */
    public function setTranslations(ArrayCollection $translations)
    {
        $this->translations->clear();
        foreach ($translations as $translation){
            $this->addTranslation($translation);
        }
        return $this;
    }

    /**
     * @param ServiceCategoryTranslation $translation
     * @return ServiceCategory
     */
    public function addTranslation(ServiceCategoryTranslation $translation){
        /* this is a way to keep the integerity */
        $translation->setServiceCategory($this);
        if(!$this->translation){
            $this->translations = new ArrayCollection();
        }
        $this->translations->add($translation);
        return $this;
    }

    /**
     * @param ServiceCategoryTranslation $translation
     * @return ServiceCategory
     */
    public function removeStandort(ServiceCategoryTranslation $translation){
        $this->translations->removeElement($translation);
        return $this;
    }
}    


class ServiceCategoryTranslation
{
    /**
     * @ManyToOne(targetEntity="ServiceCategory", inversedBy="translations")
     * @JoinColumn(name="translatable_id", referencedColumnName="id")
     **/
    private $serviceCategory;

    /**
     * @param ServiceCategoryTranslation $translation
     * @return ServiceCategoryTranslation
     */
    public function setServiceCategory(ServiceCategory $serviceCategory){
        $this->serviceCategory = $serviceCategory;
        return $this;
    }

    /* getter analog */
}

你应该检查symfony和条令文档:我不确定你是否阅读了我刚刚写的内容,但尽管所有的文档都没有回答这个问题,顺便说一句,我在这里看了一下,所以请不要转发给我更多的文档,但它没有回答如何填写这个表格所有的文档都是关于获取数据的从DB或设置数据到一个带有setter的表,但如果你看一下代码,我不知道这些都不能回答你的问题,part Relationship Mapping Metadata:,只需将文档中的实体“Product”替换为“ServiceCategoryTranslation”,将文档中的“Category”替换为“ServiceCategory”,当然,首先您需要在表service\u category\u translation中添加列category\u id。service\u category\u translations中的引用字段是什么?它丢了吗?它是可翻译的吗?这是M对N的关系吗?@AndreasDyballa在对话框中说,它的可翻译_id链接到服务类别中的id,但在类中没有指定