我的教义有一个星期的问题,我找不到解决办法。
这是我的体系结构:
autoload.php
$autoload['libraries'] = array('Twig', 'Email', 'Doctrine');
HomeController.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class HomeController extends CI_Controller {
/**
* main method
*/
public function index()
{
$em = $this->doctrine->em;
$listNews = $em->getRepository('News');
$this->twig->display('main/home/home.html.twig', array());
}
}
Doctrine.php
<?php
use Doctrine\Common\ClassLoader,
Doctrine\ORM\Configuration,
Doctrine\ORM\EntityManager,
Doctrine\Common\Cache\ArrayCache,
Doctrine\DBAL\Logging\EchoSQLLogger;
class Doctrine {
public $em = null;
public function __construct()
{
// load database configuration from CodeIgniter
require_once APPPATH.'config/database.php';
// Set up class loading. You could use different autoloaders, provided by your favorite framework,
// if you want to.
$doctrineClassLoader = new ClassLoader('Doctrine', APPPATH.'libraries');
$doctrineClassLoader->register();
$entitiesClassLoader = new ClassLoader('Entity', APPPATH.'models');
$entitiesClassLoader->register();
$proxiesClassLoader = new ClassLoader('Proxies', APPPATH.'models/proxies');
$proxiesClassLoader->register();
// Set up caches
$config = new Configuration;
$cache = new ArrayCache;
$config->setMetadataCacheImpl($cache);
$driverImpl = $config->newDefaultAnnotationDriver(array(APPPATH.'models/Entities'));
$config->setMetadataDriverImpl($driverImpl);
$config->setQueryCacheImpl($cache);
$config->setQueryCacheImpl($cache);
// Proxy configuration
$config->setProxyDir(APPPATH.'/models/proxies');
$config->setProxyNamespace('Proxies');
// Set up logger
$logger = new EchoSQLLogger;
$config->setSQLLogger($logger);
$config->setAutoGenerateProxyClasses( TRUE );
// Database connection information
$connectionOptions = array(
'driver' => 'pdo_mysql',
'user' => $db['default']['username'],
'password' => $db['default']['password'],
'host' => $db['default']['hostname'],
'dbname' => $db['default']['database']
);
// Create EntityManager
$this->em = EntityManager::create($connectionOptions, $config);
}
}
News.php
<?php
namespace Entity;
/**
* Created by PhpStorm.
* User: laurent P.
* Date: 17/11/2018
* Time: 00:36
*/
/**
* @Entity
* @Table(name="News")
*/
class News
{
/**
* @Id
* @Column(type="integer")
* @GeneratedValue
*/
private $id;
/**
* @var string
* @Column(type="string", length=100)
*/
private $title;
/**
* @var string
* @Column(type="string", length=4000)
*/
private $content;
/**
* @Column(type="datetime")
*/
private $createdDate;
/**
* @Column(type="datetime")
*/
private $updatedDate;
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
/**
* @param mixed $id
* @return News
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* @return mixed
*/
public function getTitle()
{
return $this->title;
}
/**
* @param mixed $title
* @return News
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* @return mixed
*/
public function getContent()
{
return $this->content;
}
/**
* @param mixed $content
* @return News
*/
public function setContent($content)
{
$this->content = $content;
return $this;
}
/**
* @return mixed
*/
public function getCreatedDate()
{
return $this->createdDate;
}
/**
* @param mixed $createdDate
* @return News
*/
public function setCreatedDate($createdDate)
{
$this->createdDate = $createdDate;
return $this;
}
/**
* @return mixed
*/
public function getUpdatedDate()
{
return $this->updatedDate;
}
/**
* @param mixed $updatedDate
* @return News
*/
public function setUpdatedDate($updatedDate)
{
$this->updatedDate = $updatedDate;
return $this;
}
}
这就是我得到的:
遇到未捕获的异常
类型:学说\公共\持久性\映射\映射异常
消息:“新闻”类不存在
文件名: C:\ wamp64 \ www \ cubasanga \ vendor \ doctrine \ persistence \ lib \ Doctrine \ Common \ Persistence \ Mapping \ MappingException.php
行号:93
回溯:
文件: C:\ wamp64 \ www \ cubasanga \ vendor \ doctrine \ persistence \ lib \ Doctrine \ Common \ Persistence \ Mapping \ RuntimeReflectionService.php 行:24函数:nonExistingClass
文件: C:\ wamp64 \ www \ cubasanga \ vendor \ doctrine \ persistence \ lib \ Doctrine \ Common \ Persistence \ Mapping \ AbstractClassMetadataFactory.php 行:251函数:getParentClasses
文件: C:\ wamp64 \ www \ cubasanga \ vendor \ doctrine \ persistence \ lib \ Doctrine \ Common \ Persistence \ Mapping \ AbstractClassMetadataFactory.php 行:284函数:getParentClasses
文件: C:\ wamp64 \ www \ cubasanga \ vendor \ doctrine \ orm \ lib \ Doctrine \ ORM \ Mapping \ ClassMetadataFactory.php 行:78函数:loadMetadata
文件: C:\ wamp64 \ www \ cubasanga \ vendor \ doctrine \ persistence \ lib \ Doctrine \ Common \ Persistence \ Mapping \ AbstractClassMetadataFactory.php 行:183功能:loadMetadata
文件: C:\ wamp64 \ www \ cubasanga \ vendor \ doctrine \ orm \ lib \ Doctrine \ ORM \ EntityManager.php 行:283函数:getMetadataFor
文件: C:\ wamp64 \ www \ cubasanga \ vendor \ doctrine \ orm \ lib \ Doctrine \ ORM \ Repository \ DefaultRepositoryFactory.php 行:44函数:getClassMetadata
文件: C:\ wamp64 \ www \ cubasanga \ vendor \ doctrine \ orm \ lib \ Doctrine \ ORM \ EntityManager.php 行:713函数:getRepository
文件:C:\ wamp64 \ www \ cubasanga \ src \ controllers \ HomeController.php行: 12功能:getRepository
文件:C:\ wamp64 \ www \ cubasanga \ index.php行:316功能: require_once
我尝试了所有操作,但我不明白为什么我的实体无法加载。我想问题出在ClassLoader。
有人可以告诉我我的错误在哪里吗?