【问题标题】:symfony 2 how to create or map entity in different bundlessymfony 2 如何在不同的包中创建或映射实体
【发布时间】:2015-02-23 15:35:34
【问题描述】:

我的项目有不同的捆绑包。我想在不同的包中创建或划分实体,我该如何创建它。我是 symfony 的新手,请帮助我。我创建但无法正确映射。具有主键的表不能在另一个包中使用。

这是我的实体

namespace DomainBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * WebsiteDomainConfigTest
 *
 * @ORM\Table(name="website_domain_config_test", indexes={@ORM\Index(name="fk_website_domain_config_test_1_idx", columns={"vendor_id"}), @ORM\Index(name="fk_website_domain_config_test_2_idx", columns={"country_id"})})
 * @ORM\Entity
 */
class WebsiteDomainConfigTest 
{
    /**
     * @var string
     *
     * @ORM\Column(name="domain", type="string", length=255, nullable=true)
     */
    private $domain;

    /**
     * @var string
     *
     * @ORM\Column(name="vendor_code", type="string", length=15, nullable=true)
     */
    private $vendorCode;

    /**
     * @var string
     *
     * @ORM\Column(name="domain_path", type="string", length=255, nullable=true)
     */
    private $domainPath;

    /**
     * @var string
     *
     * @ORM\Column(name="assets_path", type="string", length=45, nullable=true)
     */
    private $assetsPath;

    /**
     * @var string
     *
     * @ORM\Column(name="language", type="string", length=3, nullable=true)
     */
    private $language;

    /**
     * @var string
     *
     * @ORM\Column(name="affiliate", type="string", length=25, nullable=true)
     */
    private $affiliate;

    /**
     * @var string
     *
     * @ORM\Column(name="affiliate_logo", type="string", length=255, nullable=true)
     */
    private $affiliateLogo;

    /**
     * @var string
     *
     * @ORM\Column(name="affiliate_address", type="string", length=255, nullable=true)
     */
    private $affiliateAddress;

    /**
     * @var integer
     *
     * @ORM\Column(name="status", type="integer", nullable=true)
     */
    private $status;

    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * @var \MobileSplash\SplashRequestBundle\Entity\Countries
     *
     * @ORM\ManyToOne(targetEntity="MobileSplash\SplashRequestBundle\Entity\Countries")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="country_id", referencedColumnName="id")
     * })
     */
    private $country;

    /**
     * @var \MobileSplash\SplashRequestBundle\Entity\Vendors
     *
     * @ORM\ManyToOne(targetEntity="MobileSplash\SplashRequestBundle\Entity\Vendors")
     * @ORM\JoinColumns({
     * @ORM\JoinColumn(name="vendor_id", referencedColumnName="id")
     * })
     */
    private $vendor;



    /**
     * Set domain
     *
     * @param string $domain
     * @return WebsiteDomainConfigTest
     */
    public function setDomain($domain)
    {
        $this->domain = $domain;

        return $this;
    }

    /**
     * Get domain
     *
     * @return string 
     */
    public function getDomain()
    {
        return $this->domain;
    }

    /**
     * Set vendorCode
     *
     * @param string $vendorCode
     * @return WebsiteDomainConfigTest
     */
    public function setVendorCode($vendorCode)
    {
        $this->vendorCode = $vendorCode;

        return $this;
    }

    /**
     * Get vendorCode
     *
     * @return string 
     */
    public function getVendorCode()
    {
        return $this->vendorCode;
    }

    /**
     * Set domainPath
     *
     * @param string $domainPath
     * @return WebsiteDomainConfigTest
     */
    public function setDomainPath($domainPath)
    {
        $this->domainPath = $domainPath;

        return $this;
    }

    /**
     * Get domainPath
     *
     * @return string 
     */
    public function getDomainPath()
    {
        return $this->domainPath;
    }

    /**
     * Set assetsPath
     *
     * @param string $assetsPath
     * @return WebsiteDomainConfigTest
     */
    public function setAssetsPath($assetsPath)
    {
        $this->assetsPath = $assetsPath;

        return $this;
    }

    /**
     * Get assetsPath
     *
     * @return string 
     */
    public function getAssetsPath()
    {
        return $this->assetsPath;
    }

    /**
     * Set language
     *
     * @param string $language
     * @return WebsiteDomainConfigTest
     */
    public function setLanguage($language)
    {
        $this->language = $language;

        return $this;
    }

    /**
     * Get language
     *
     * @return string 
     */
    public function getLanguage()
    {
        return $this->language;
    }

    /**
     * Set affiliate
     *
     * @param string $affiliate
     * @return WebsiteDomainConfigTest
     */
    public function setAffiliate($affiliate)
    {
        $this->affiliate = $affiliate;

        return $this;
    }

    /**
     * Get affiliate
     *
     * @return string 
     */
    public function getAffiliate()
    {
        return $this->affiliate;
    }

    /**
     * Set affiliateLogo
     *
     * @param string $affiliateLogo
     * @return WebsiteDomainConfigTest
     */
    public function setAffiliateLogo($affiliateLogo)
    {
        $this->affiliateLogo = $affiliateLogo;

        return $this;
    }

    /**
     * Get affiliateLogo
     *
     * @return string 
     */
    public function getAffiliateLogo()
    {
        return $this->affiliateLogo;
    }

    /**
     * Set affiliateAddress
     *
     * @param string $affiliateAddress
     * @return WebsiteDomainConfigTest
     */
    public function setAffiliateAddress($affiliateAddress)
    {
        $this->affiliateAddress = $affiliateAddress;

        return $this;
    }

    /**
     * Get affiliateAddress
     *
     * @return string 
     */
    public function getAffiliateAddress()
    {
        return $this->affiliateAddress;
    }

    /**
     * Set status
     *
     * @param integer $status
     * @return WebsiteDomainConfigTest
     */
    public function setStatus($status)
    {
        $this->status = $status;

        return $this;
    }

    /**
     * Get status
     *
     * @return integer 
     */
    public function getStatus()
    {
        return $this->status;
    }

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

    /**
     * Set country
     *
     * @param \MobileSplash\SplashRequestBundle\Entity\Countries $country
     * @return WebsiteDomainConfigTest
     */
    public function setCountry(\MobileSplash\SplashRequestBundle\Entity\Countries $country = null)
    {
        $this->country = $country;

        return $this;
    }

    /**
     * Get country
     *
     * @return \MobileSplash\SplashRequestBundle\Entity\Countries 
     */
    public function getCountry()
    {
        return $this->country;
    }

    /**
     * Set vendor
     *
     * @param \MobileSplash\SplashRequestBundle\Entity\Vendors $vendor
     * @return WebsiteDomainConfigTest
     */
    public function setVendor(\MobileSplash\SplashRequestBundle\Entity\Vendors $vendor = null)
    {
        $this->vendor = $vendor;

        return $this;
    }

    /**
     * Get vendor
     *
     * @return \MobileSplash\SplashRequestBundle\Entity\Vendors 
     */
    public function getVendor()
    {
        return $this->vendor;
    }
}

【问题讨论】:

标签: php symfony


【解决方案1】:

在你的注解中使用这样的命名空间:

targetEntity="\Mj\FooBundle\Entity\Foo"

【讨论】:

  • 在“DomainBundle\Entity\WebsiteDomainConfigTest#country”中找不到目标实体 DomainBundle\Entity\Countries。
  • @VikasShinde 嗯,在 mobilespalsh 之前添加 \ 怎么样
猜你喜欢
  • 2017-04-27
  • 1970-01-01
  • 2013-07-26
  • 1970-01-01
  • 2014-04-09
  • 1970-01-01
  • 1970-01-01
  • 2013-10-20
  • 1970-01-01
相关资源
最近更新 更多