Symfony2:实体创建但是,给类不存在

时间:2014-03-31 13:56:23

标签: php symfony doctrine-orm entity

我创建了一个Entity类db_logs

namespace Acme\SuperBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
class db_logs

{
/**
 * @ORM\Column(type="integer", length=11,  columnDefinition="INT(11) NOT NULL AUTO_INCREMENT")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
protected $id;

/**
 * @ORM\Column(type="datetime", columnDefinition="TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
 */
protected $date;

/**
 * @ORM\Column(type="text", columnDefinition="TEXT  NOT NULL")
 */
protected $log;
}

Doctrine entiry完美地创建所有数据库表

php app/console doctrine:generate:entities Acme\SuperBundle\Entity

现在我尝试在DefaultController中使用以下代码:

namespace Acme\SuperBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class DefaultController extends Controller
{
    public function indexAction()
    {
        /*
         * Test connect db
         */
        $mysql_fetcher = $this->getDoctrine()
                    ->getRepository('AcmeSuperBundle:db_logs')    
                    ->findAll();
        $output=array("latest"=>$mysql_fetcher);   
        return $this->render('AcmeSuperBundle:Default:index.html.twig', $output);
    }  
}

但是当我去web / app_dev.php

我收到此消息错误。出了什么问题?

Class 'Acme\SuperBundle\Entity\db_logs' does not exist
500 Internal Server Error - MappingException 

我确定实体文件存在。为什么Symfony2找不到实体文件?

1 个答案:

答案 0 :(得分:0)

您必须将其包含在DefaultController

use Acme\SuperBundle\Entity\db_logs;

另外,您是否创建了db_logs存储库?

然后,将这几个有用的注释添加到db_logs实体。

/**
 *
 * @ORM\Table(name="db_logs")
 * @ORM\Entity(repositoryClass="Acme\SuperBundle\Repository\db_logsRepository")
 */
class db_logs {

  // ...
}