我该如何解决这个问题?
<?php
namespace entity;
/**
* @Entity @Table(name="debt")
* */
class Debt {
/**
* @Id @Column(type="integer") @GeneratedValue
* */
protected $id;
/**
* @Column(type="integer")
* */
protected $value;
/**
* @ManyToOne(targetEntity="people", inversedBy="debts")
* */
protected $who;
public function setValue($value) {
$this->value = $value;
}
public function setWho(Who $who) {
$this->who = $who;
}
public function getValue() {
return $this->value;
}
public function getWho() {
return $this->who;
}
}
<?php
namespace entity;
/**
* @Entity @Table(name="people")
* */
class People {
/**
* @Id @Column(type="integer") @GeneratedValue
* */
protected $id;
/**
* @Column(type="string")
* */
protected $name;
/**
* @OneToMany(targetEntity="debt", mappedBy="who")
* */
protected $debts;
public function setName($name) {
$this->name = $name;
}
public function assignDebt(Debt $debt) {
$this->debts[] = $debt;
}
public function getName() {
return $this->name;
}
public function getDebts() {
return $this->debts;
}
}
当我尝试: $em->getRepository("entityDebt")->findAll()
我收到此错误:
警告:require(C:\Windows\TEMP__CG__entitypeople.php):无法打开流:C:\xampp\htdocs\skola\vendor\doctrine\orm\lib\Doctrine\ORM\Proxy\ProxyFactory.php 第 92 行中没有这样的文件或目录
致命错误: require(): 打开失败需要 'C:\Windows\TEMP__CG__entitypeople.php' (include_path='。C:\xampp\php\pear;C:\pear;\xampp\php\PEAR') in C:\xampp\htdocs\skola\vendor\doctrine\orm\lib\Doctrine\ORM\Proxy\ProxyFactory.php 在第 92 行
此外,当我删除此部分时,它可以工作:
/**
* @ManyToOne(targetEntity="people", inversedBy="debts")
* */
protected $who;
您需要在 Doctrine 中设置代理目录
该目录用于编写教义的代理,当然需要具有写入权限
http://docs.doctrine-project.org/en/2.0.x/reference/configuration.html#proxy-directory-required
您必须先设置代理类的生成。您可以通过设置配置来启用自动生成原则代理类:$config->setAutoGenerateProxyClasses(tr
$config = new Configuration;
$config->setMetadataCacheImpl($cache);
$driverImpl = $config->newDefaultAnnotationDriver('/path/to/lib/MyProject/Entities');
$config->setMetadataDriverImpl($driverImpl);
$config->setQueryCacheImpl($cache);
$config->setProxyDir('/path/to/myproject/lib/MyProject/Proxies');
$config->setProxyNamespace('MyProjectProxies');
if ($applicationMode == "development") {
$config->setAutoGenerateProxyClasses(true);
} else {
$config->setAutoGenerateProxyClasses(false);
}