我该如何解决这个问题?
<?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("entity\Debt")->findAll()
我收到此错误时:
警告:require(C:\ Windows \ TEMP__CG__entitypeople.php):无法打开流:C:\ xampp \ htdocs \ skola \ vendor \ doctrine \ orm \ lib \ Doctrine \ ORM \ Proxy中没有此类文件或目录第92行上的\ ProxyFactory.php
致命错误:require():无法打开所需的'C:\ Windows \ TEMP__CG__entitypeople.php'(include_path ='。; C:\ xampp \ php \ pear; C:\ pear; \ xampp \ php \ PEAR' )在第92行的C:\ xampp \ htdocs \ skola \ vendor \ doctrine \ orm \ lib \ Doctrine \ ORM \ Proxy \ ProxyFactory.php
当我删除这部分时,它也有效:
/**
* @ManyToOne(targetEntity="people", inversedBy="debts")
* */
protected $who;
答案 0 :(得分:4)
您需要在Doctrine
中设置代理目录该目录用于编写学说的代理,当然还需要具有写权限
http://docs.doctrine-project.org/en/2.0.x/reference/configuration.html#proxy-directory-required
答案 1 :(得分:0)
您必须先设置代理类的生成。您可以通过设置config来启用自动生成doctrine代理类:$ config-&gt; 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('MyProject\Proxies');
if ($applicationMode == "development") {
$config->setAutoGenerateProxyClasses(true);
} else {
$config->setAutoGenerateProxyClasses(false);
}