打开所需的'application / models / proxies / __ CG__modelsCountry.php'失败

时间:2012-10-24 17:49:07

标签: php doctrine pear proxyfactory

我的实体CountryCity的关系OneToMany来自CountryManyToOne来自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行可以在doctrine2 (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);

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:1)

我遇到了这个问题,因为我在运行之前尝试加载灯具:

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

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

doctrine命令&#39; generate-proxies&#39;很可能也解决了这个问题:

./vendor/bin/doctrine-module orm:generate-proxies