【问题标题】:Class IDP\Bundle\Entity\Portfolio is not a valid entity or mapped super class类 IDP\Bundle\Entity\Portfolio 不是有效的实体或映射的超类
【发布时间】:2012-09-21 03:39:39
【问题描述】:

我是 symfony2 的新手。我创建了一个称为投资组合控制器的基本控制器和该控制器的一些索引视图。我也创建了一个实体类,但它给出了错误。

我的控制器是

<?php
namespace IDP\Bundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
 class PortfolioController extends Controller {

    public function indexAction() {
     $product = $this->getDoctrine()
      ->getRepository('IDPBundle:Portfolio')
      ->find(1);
    return $this->render('IDPBundle:Portfolio:index.html.twig');
   }

} 

在 src/IDP/Bundle/Entity/Portfolio.php 里面

 <?php
 namespace IDP\Bundle\Entity;
 use Doctrine\ORM\Mapping as ORM;
 use Symfony\Component\Validator\Constraints as Assert;
 class Portfolio
 {
   private $id;
   private $user_id;
   private $portfolio_name;
   private $description;
   private $permalink;
   private $sharingCode;
   private $shared;
   private $shared_portfolio_calls;
   private $patentgroup_id;

public function __construct()
{
    $this->portfolioGroups = new \Doctrine\Common\Collections\ArrayCollection();
}
public function getId()
{
    return $this->id;
}
public function setName($portfolio_name)
{
    $this->name = $portfolio_name;
}
public function setDescription($description)
{
    $this->description = $description;
}
public function getDescription()
{
    return $this->description;
}
public function setSharingCode($sharingCode)
{
    $this->sharingCode = $sharingCode;
}
public function getSharingCode()
{
    return $this->sharingCode;
}
public function setShared($shared)
{
    $this->shared = $shared;
}
public function getShared()
{
    return $this->shared;
}
public function getUser()
{
    return $this->user;
}
}

我的表格名称是 pm_portfolios,它包含我在投资组合类中提到的所有字段。

谁能告诉我我做错了什么?

【问题讨论】:

    标签: php symfony doctrine-orm


    【解决方案1】:

    您的实体缺少所有 ORM 元数据,例如类本身的 @ORM\Entity 和其属性的其他元数据。见the example from the docs

    【讨论】:

      【解决方案2】:

      您的实体类没有任何 ORM 元数据。试试这样的

       <?php
      
      namespace IDP\Bundle\Entity;
      
       use Doctrine\ORM\Mapping as ORM;
       use Symfony\Component\Validator\Constraints as Assert;
       /**
       * IDP\Bundle\Entity\Portfolio
       * @ORM\Table(name="pm_portfolios")
       */
      class Portfolio
      {
      /**
       * @var integer $id
       */
      private $id;
      
      /**
       * @var integer $user_id
       */
      private $user_id;
      
      /**
       * @var string $portfolio_name
       */
      private $portfolio_name;
      
      /**
       * @var text $description
       */
      private $description;
      
      /**
       * @var string $permalink
       */
      private $permalink;
      
      /**
       * @var string $sharing_code
       */
      private $sharing_code;
      
      /**
       * @var boolean $shared
       */
      private $shared;
      
      /**
       * @var integer $shared_portfolio_calls
       */
      private $shared_portfolio_calls;
      
      /**
       * @var integer $patentgroup_id
       */
      private $patentgroup_id;
      
      
      /**
       * Get id
       *
       * @return integer 
       */
      public function getId()
      {
          return $this->id;
      }
      
      /**
       * Set user_id
       *
       * @param integer $userId
       */
      public function setUserId($userId)
      {
          $this->user_id = $userId;
      }
      
      /**
       * Get user_id
       *
       * @return integer 
       */
      public function getUserId()
      {
          return $this->user_id;
      }
      
      /**
       * Set portfolio_name
       *
       * @param string $portfolioName
       */
      public function setPortfolioName($portfolioName)
      {
          $this->portfolio_name = $portfolioName;
      }
      
      /**
       * Get portfolio_name
       *
       * @return string 
       */
      public function getPortfolioName()
      {
          return $this->portfolio_name;
      }
      
      /**
       * Set description
       *
       * @param text $description
       */
      public function setDescription($description)
      {
          $this->description = $description;
      }
      
      /**
       * Get description
       *
       * @return text 
       */
      public function getDescription()
      {
          return $this->description;
      }
      
      /**
       * Set permalink
       *
       * @param string $permalink
       */
      public function setPermalink($permalink)
      {
          $this->permalink = $permalink;
      }
      
      /**
       * Get permalink
       *
       * @return string 
       */
      public function getPermalink()
      {
          return $this->permalink;
      }
      
      /**
       * Set sharing_code
       *
       * @param string $sharingCode
       */
      public function setSharingCode($sharingCode)
      {
          $this->sharing_code = $sharingCode;
      }
      
      /**
       * Get sharing_code
       *
       * @return string 
       */
      public function getSharingCode()
      {
          return $this->sharing_code;
      }
      
      /**
       * Set shared
       *
       * @param boolean $shared
       */
      public function setShared($shared)
      {
          $this->shared = $shared;
      }
      
      /**
       * Get shared
       *
       * @return boolean 
       */
      public function getShared()
      {
          return $this->shared;
      }
      
      /**
       * Set shared_portfolio_calls
       *
       * @param integer $sharedPortfolioCalls
       */
      public function setSharedPortfolioCalls($sharedPortfolioCalls)
      {
          $this->shared_portfolio_calls = $sharedPortfolioCalls;
      }
      
      /**
       * Get shared_portfolio_calls
       *
       * @return integer 
       */
      public function getSharedPortfolioCalls()
      {
          return $this->shared_portfolio_calls;
      }
      
      /**
       * Set patentgroup_id
       *
       * @param integer $patentgroupId
       */
      public function setPatentgroupId($patentgroupId)
      {
          $this->patentgroup_id = $patentgroupId;
      }
      
      /**
       * Get patentgroup_id
       *
       * @return integer 
       */
      public function getPatentgroupId()
      {
          return $this->patentgroup_id;
      }
      

      }

      【讨论】:

        猜你喜欢
        • 2018-01-15
        • 2011-12-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-02-12
        • 1970-01-01
        • 2014-02-21
        • 2013-02-05
        相关资源
        最近更新 更多