i具有 Country
和 City
的实体,与 Country
的关系 OneToMany
和 City
的 ManyToOne
,如下:
Country.php
<?php
namespace models;
use DoctrineORMMapping as ORM;
use GedmoMappingAnnotation as Gedmo,
DoctrineCommonCollectionsArrayCollection;
/**
* @ORMEntity(repositoryClass="modelsrepositoryCountryRepository")
* @ORMTable(name="Country")
*
*/
class Country{
/**
* @ORMId
* @ORMColumn(type="integer")
* @ORMGeneratedValue
*/
private $id;
/**
* @ORMColumn(type="string", length=255, nullable=false)
*/
private $name;
/**
* @var datetime $created
*
* @GedmoTimestampable(on="create")
* @ORMColumn(type="datetime")
*/
private $created;
/**
* @ORMOneToMany(targetEntity="modelsCity",mappedBy="country")
*/
private $cities;
//getters and setters
}
City.php
class City{
/**
* @ORMId
* @ORMColumn(type="integer")
* @ORMGeneratedValue
*/
private $id;
/**
* @ORMManyToOne(targetEntity="modelsCountry")
*/
private $country;
/**
* @ORMColumn(type="string", length=255, nullable=false)
*/
private $name;
//getters and setters
}
当我尝试与CityID一起取出城市(例如1)时,
$city_ = $this->doctrine->em->find('modelsCity', 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:phpincludes"
;
; 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{
/**
* @ORMId
* @ORMColumn(type="integer")
* @ORMGeneratedValue
*/
private $id;
/**
* @ORMColumn(type="string", length=255, nullable=false)
*/
private $description;
}
它运作良好
$sector = $this->doctrine->em->find('modelsSector', 1);
sudo mkdir application/models/proxies
效果完美。Doctrine
没有为我创建proxies
文件夹。
我遇到了这个问题,因为我在运行之前试图加载固定装置:
./vendor/bin/doctrine-module orm:schema-tool:create
当我运行此操作时,我的代理课程就会生成,并且错误消失了。
学说命令"生成proxies'也可能已经解决了此问题:
./vendor/bin/doctrine-module orm:generate-proxies