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


Symfony2: Entity created but, give class does not exist

我创建了一个实体类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;
}

条令实体完美创建所有数据库表

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找不到实体文件?

您必须将其包含在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 {
  // ...
}