I have entities Country
and City
with relationship OneToMany
from Country
and ManyToOne
from City
, which are as follows :
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
}
When I try to fetch a city with cityId (say 1),
$city_ = $this->doctrine->em->find('models\City', 1);
the error I get is
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
The line no 93 can viewed at doctrine2 (github)
NOTE:
1 - my /etc/php5/apache2/php.ini
is
;;;;;;;;;;;;;;;;;;;;;;;;;
; 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 - When I fetch entity having no relationship with any other entity, for eg
class Sector{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
*/
private $id;
/**
* @ORM\Column(type="string", length=255, nullable=false)
*/
private $description;
}
it works well
$sector = $this->doctrine->em->find('models\Sector', 1);
sudo mkdir application/models/proxies
works perfectly.Doctrine
was not creatingproxies
folder for me.