次のようなエンティティがCountry
あり、 fromとfromのCity
関係があります。OneToMany
Country
ManyToOne
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);