i am using doctrine 2 with Zendframework 2
i am trying to return an object but keep getting this error:
Your proxy directory must be writable
this is my query:
$this->getEntityManager()
->getRepository('Messages\Entity\Messages')
->findOneBy(array('id' => 6,
'receiverId' => 16
));
However, the same query return an array without any problems re:
$qb = $this->getEntityManager()->createQueryBuilder();
$qb->select(array('u'))
->from('Messages\Entity\Messages','u')
->where('u.id = :id')
->andWhere('u.receiverUserId = :receiverId')
->setParameter('receiverId',16)
->setParameter('id',(int)6);
$query = $qb->getQuery();
return $data = $query->getArrayResult();
If you are using Setup::createAnnotationMetadataConfiguration
you can simply fix it by
data/DoctrineORMModule/Proxy
chmod -R 755 data/DoctrineORMModule/Proxy
In your bootstrap include the path to the data directory as in:
Setup::createAnnotationMetadataConfiguration(array(__DIR__ . "/src/models"), $this->isDevMode, "data/DoctrineORMModule/Proxy")
That fixed it for me.
Proxies are simple classes which extends your actual entities and used internally by doctrine to hydrate associations of your entities by lazy-loading them. Doctrine decides to use or not to use a proxy instances on runtime for different situations and it really depends on your queries and associations in your entities. You may want to read about this subject in-depth at official documentation.
In your case, doctrine trying to generate a proxy class for your Messages
entity but your proxy directory is simply not writable as error output's said.
This seems like misconfiguration of DoctineModule. (Assuming that you are using DoctrineORMModule to integrate doctrine with ZF2) Doctrine needs a writeable directory to put that generated proxy classes. For ZF2's view, data
directory on application root perfectly fits for this requirement.
Make sure existence of the line below in your public/index.php
:
chdir(dirname(__DIR__));
and try to use a configuration like this:
<?php
/**
* module/Application/config/module.config.php
*/
return array(
'router' => array(
// ...
),
// ...
'doctrine' => array(
'driver' => array(
//...
),
/**
* Generating proxies on runtime and using array cache instead of apc(u)
* greatly reduces the performance. So, you may want to override
* this settings on production environment.
*/
'configuration' => array(
'orm_default' => array(
'metadata_cache' => 'array',
'query_cache' => 'array',
'result_cache' => 'array',
'hydration_cache' => 'array',
'generate_proxies' => true,
'proxy_dir' => 'data/DoctrineORMModule/Proxy',
'proxy_namespace' => 'DoctrineORMModule\Proxy',
),
),
)
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With