1

我有实体CountryCityOneToManyfromCountryManyToOnefrom的关系City,如下所示:

Country.php

<?php
namespace models;

use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo,
    Doctrine\Common\Collections\ArrayCollection;
/**
 * @ORM\Entity(repositoryClass="models\repository\CountryRepository")
 * @ORM\Table(name="Country")
 *
 */
class Country{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=255, nullable=false)
     */
    private $name;

    /**
     * @var datetime $created
     *
     * @Gedmo\Timestampable(on="create")
     * @ORM\Column(type="datetime")
     */
    private $created;

    /**
     * @ORM\OneToMany(targetEntity="models\City",mappedBy="country")
     */
    private $cities;

    //getters and setters 
}

City.php

class City{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue
     */
    private $id;

   /**
     * @ORM\ManyToOne(targetEntity="models\Country")
     */

    private $country;

    /**
     * @ORM\Column(type="string", length=255, nullable=false)
     */
    private $name;

    //getters and setters
}

当我尝试使用cityId(比如1)获取一个城市时,

$city_ = $this->doctrine->em->find('models\City', 1);

我得到的错误是

Fatal error: require(): Failed opening required 'application/models/proxies/__CG__modelsCountry.php' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/MyCIApp/application/third_party/Doctrine/ORM/Proxy/ProxyFactory.php on line 93 

第 93 行可以在学说 2 (github)上查看

笔记:

1 - 我/etc/php5/apache2/php.ini

;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;

; UNIX: "/path1:/path2"
;include_path = ".:/usr/share/php"
;
; Windows: "\path1;\path2"
;include_path = ".;c:\php\includes"
;
; PHP's default setting for include_path is ".;/path/to/php/pear"
; http://php.net/include-path
;include_path=".:/usr/share/php/pear"
; The root of the PHP pages, used only if nonempty.
; if PHP was not compiled with FORCE_REDIRECT, you SHOULD set doc_root
; if you are running php as a CGI under any web server (other than IIS)
; see documentation for security issues.  The alternate is to use the
; cgi.force_redirect configuration below
; http://php.net/doc-root

2 - 当我获取与任何其他实体没有关系的实体时,例如

class Sector{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=255, nullable=false)
     */
    private $description;
}

它运作良好

$sector = $this->doctrine->em->find('models\Sector', 1);
4

2 回答 2

1

sudo mkdir application/models/proxies完美运行。Doctrine没有为我创建proxies文件夹。

于 2012-10-24T20:39:10.797 回答
1

我遇到了这个问题,因为我试图在运行之前加载固定装置:

./vendor/bin/doctrine-module orm:schema-tool:create

当我运行它时,生成了我的代理类并且错误消失了。

教义命令“生成代理”很可能也解决了这个问题:

./vendor/bin/doctrine-module orm:generate-proxies
于 2014-07-04T15:18:22.690 回答