Doctrine orm 条令2返回错误';代理目录必须是可写的';

Doctrine orm 条令2返回错误';代理目录必须是可写的';,doctrine-orm,zend-framework2,Doctrine Orm,Zend Framework2,我在ZendFramework2中使用条令2 我试图返回一个对象,但一直出现以下错误: 您的代理目录必须是可写的 这是我的疑问: $this->getEntityManager() ->getRepository('Messages\Entity\Messages') ->findOneBy(array('id' => 6,

我在ZendFramework2中使用条令2

我试图返回一个对象,但一直出现以下错误:

您的代理目录必须是可写的

这是我的疑问:

$this->getEntityManager()
                    ->getRepository('Messages\Entity\Messages')
                    ->findOneBy(array('id' => 6,
                                      'receiverId' => 16
                   ));
但是,同一查询返回的数组没有任何问题:

$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(); 

代理是一个简单的类,它扩展了您的实际实体,并在内部由条令使用,以通过它们实现实体的关联。条令决定在不同的情况下在运行时使用或不使用代理实例,这实际上取决于实体中的查询和关联。您可能想在上深入了解这个主题

在您的情况下,Dority试图为您的
消息
实体生成代理类,但正如错误输出所说,您的代理目录是不可写的

这似乎是对DoctineModule的错误配置。(假设您正在使用将doctrine与ZF2集成)doctrine需要一个可写目录来放置生成的代理类。在ZF2看来,应用程序根目录上的
数据
目录非常适合此要求

  • 确保
    public/index.php中存在以下行:

    chdir(dirname(__DIR__));
    
  • 并尝试使用如下配置:

    <?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',
                ),
            ),
         )
     );
    

    如果您使用的是
    Setup::createAnnotationMetadataConfiguration
    ,只需通过

  • 在项目根目录中创建以下目录<代码>数据/DoctrineORMModule/Proxy
  • chmod-R 755数据/DoctrineORMModule/Proxy
  • 在引导中包括数据目录的路径,如所示:

    Setup::createAnnotationMetadataConfiguration(数组(\uuu DIR.\uuu.'/src/models)),$this->isDevMode,“数据/DoctrineORMModule/Proxy”)


    这为我解决了问题。

    如果您使用的是Fedora 24,请输入以下命令:

    semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/YOUR_SITE/data';
    restorecon -v '/var/www/html/YOUR_SITE/data'
    

    这样,您就可以更改
    /var/www/html
    的标签,并授予
    httpd

    写入权限,以检查目录的权限。它不仅可以由您(用户)写入,还可以由组写入。右键单击文件夹,然后转到属性,然后是权限,或者使用
    chmod
    (实际上取决于您的特定php设置)从终端执行操作。我可能会遇到类似的错误。如果您正在通过命令行运行脚本/进程,就像我试图做的那样,请确保您使用的是正确的用户。有时候,向apache用户sudo以确保您对各种文件和文件夹拥有权限更容易。你好,Foozy,我尝试了您的建议,但没有成功。它仍然给出相同的错误消息。你有什么建议吗。我感谢你的帮助。谢谢这个问题很清楚:您的代理目录(在我的示例中是数据)必须可由http服务器的用户写入。你的操作系统和http服务器是什么?你好。很抱歉什么是操作系统?。对于amy Http服务器,我使用的是wamp:对于我的Http服务器,我使用的这个也帮助了我!非常感谢。