2

我怎样才能解决这个问题?

<?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\ProxyFactory 中没有这样的文件或目录。第 92 行的 php

致命错误:require():在 C 中打开所需的 'C:\Windows\TEMP__CG__entitypeople.php' (include_path='.;C:\xampp\php\pear;C:\pear;\xampp\php\PEAR') 失败:\xampp\htdocs\skola\vendor\doctrine\orm\lib\Doctrine\ORM\Proxy\ProxyFactory.php 在第 92 行

当我删除这部分时,它也可以工作:

/**
 * @ManyToOne(targetEntity="people", inversedBy="debts")
 * */
protected $who;
4

2 回答 2

4

您需要在 Doctrine 中设置代理目录

该目录用于编写学说的代理,当然需要有写权限

http://docs.doctrine-project.org/en/2.0.x/reference/configuration.html#proxy-directory-required

于 2012-11-29T22:26:14.073 回答
0

您必须首先设置代理类的生成。您可以通过设置配置启用自动生成学说代理类: $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('MyProject\Proxies');

if ($applicationMode == "development") {
    $config->setAutoGenerateProxyClasses(true);
} else {
    $config->setAutoGenerateProxyClasses(false);
}
于 2015-03-11T10:49:16.503 回答