【问题标题】:Can't make ManyToOne to work无法让 ManyToOne 工作
【发布时间】:2012-11-18 02:49:27
【问题描述】:

我该如何解决这个问题?

<?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-&gt;getRepository("entity\Debt")-&gt;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' ) 在第 92 行的 C:\xampp\htdocs\skola\vendor\doctrine\orm\lib\Doctrine\ORM\Proxy\ProxyFactory.php 中

当我删除这部分时它也有效:

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

【问题讨论】:

    标签: php doctrine-orm


    【解决方案1】:

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

    那个目录是用来写学说的代理的,当然需要有写权限

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-02-23
        • 2014-12-26
        • 2017-12-22
        • 2012-02-28
        • 2015-12-01
        • 2012-01-29
        • 2014-12-16
        • 2013-04-19
        相关资源
        最近更新 更多