0

我对 Symfony2 很陌生,我在我的项目中创建了一个实体类,但我得到了一个错误。我用谷歌搜索了很多解决方案,但找不到。这是我的控制器

<?php
namespace IDP\Bundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use IDP\Bundle\Entity\Portfolio;

class PortfolioController extends Controller {

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

}

我在实体文件夹中的 Portfolio.php 就像

<?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;
}
}

我得到的错误是

 No mapping file found named 'IDP.Bundle.Entity.Portfolio.php' for class 'IDP\Bundle\Entity\Portfolio'.

我错过了什么吗?谢谢?

4

2 回答 2

2

您需要将 @ORM\Entity 添加到您的 Entity 类中。尝试:

<?php

namespace IDP\Bundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;

/**
* IDP\Bundle\Entity\Portfolio
*
* @ORM\Entity
* @ORM\Table(name="pm_portfolios")
*/
class Portfolio
{

您还需要将 ORM 映射添加到您的投资组合实体的每个属性(请参阅http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/annotations-reference.html#annref-列)。

于 2012-05-28T07:48:25.753 回答
0

我遇到了同样的错误,并找到了同时使用注释和 yml 的原因..一次只使用一个...

于 2012-09-13T17:03:03.730 回答