• <small id='lZkbb'></small><noframes id='lZkbb'>

        <legend id='lZkbb'><style id='lZkbb'><dir id='lZkbb'><q id='lZkbb'></q></dir></style></legend>

          <bdo id='lZkbb'></bdo><ul id='lZkbb'></ul>
        <i id='lZkbb'><tr id='lZkbb'><dt id='lZkbb'><q id='lZkbb'><span id='lZkbb'><b id='lZkbb'><form id='lZkbb'><ins id='lZkbb'></ins><ul id='lZkbb'></ul><sub id='lZkbb'></sub></form><legend id='lZkbb'></legend><bdo id='lZkbb'><pre id='lZkbb'><center id='lZkbb'></center></pre></bdo></b><th id='lZkbb'></th></span></q></dt></tr></i><div id='lZkbb'><tfoot id='lZkbb'></tfoot><dl id='lZkbb'><fieldset id='lZkbb'></fieldset></dl></div>
      1. <tfoot id='lZkbb'></tfoot>

        导入注释时出现问题

        Trouble with importing annotations(导入注释时出现问题)
          <bdo id='vWfhR'></bdo><ul id='vWfhR'></ul>

            <tbody id='vWfhR'></tbody>

          <small id='vWfhR'></small><noframes id='vWfhR'>

          <i id='vWfhR'><tr id='vWfhR'><dt id='vWfhR'><q id='vWfhR'><span id='vWfhR'><b id='vWfhR'><form id='vWfhR'><ins id='vWfhR'></ins><ul id='vWfhR'></ul><sub id='vWfhR'></sub></form><legend id='vWfhR'></legend><bdo id='vWfhR'><pre id='vWfhR'><center id='vWfhR'></center></pre></bdo></b><th id='vWfhR'></th></span></q></dt></tr></i><div id='vWfhR'><tfoot id='vWfhR'></tfoot><dl id='vWfhR'><fieldset id='vWfhR'></fieldset></dl></div>
        • <legend id='vWfhR'><style id='vWfhR'><dir id='vWfhR'><q id='vWfhR'></q></dir></style></legend>

            1. <tfoot id='vWfhR'></tfoot>
                • 本文介绍了导入注释时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在开发一个 CodeIgniter 项目,在该项目中我使用了 Doctrine2 和 Symfony2 Validator 组件.

                  I'm working on a CodeIgniter project in which I'm using Doctrine2 and the Symfony2 Validator component.

                  我所有的 Doctrine2 实体 使用 DoctrineORMMapping 并且实体管理器识别它们.我的实体注释如下所示:

                  All my Doctrine2 entities use DoctrineORMMapping and the entity manager recognizes them. My entity annotation looks like this:

                  /**
                   * @Entity(repositoryClass = "UserRepository")
                   * @Table(name = "user")
                   * @HasLifecycleCallbacks()
                   */
                  

                  此时,我可以毫无困难地持久化实体.第一个问题出现在我尝试使用 Symfony2 Validator 组件时.当我尝试验证 User 对象时,出现此错误:

                  At this point, I'm able to persist entities without any trouble. The first problem arises when I try to use the Symfony2 Validator component. When I try to validate a User object, I get this error:

                  [语义错误] EntityUser 类中的注释@Entity"从未被导入.您是否忘记为此注释添加use"语句?

                  [Semantical Error] The annotation "@Entity" in class EntityUser was never imported. Did you maybe forget to add a "use" statement for this annotation?

                  这个问题的唯一修复"是通过use DoctrineMappingEntity,但我必须为我的实体使用的每个注释(表、列、多对一等).我试图弄清楚为什么我需要明确地use 每个注释类而不是它们被自动识别(不应该 use DoctrineORMMapping 授予我访问该命名空间中的所有类?).

                  The only "fix" to this issue is through use DoctrineMappingEntity, but I have to do that for every annotation being used by my entity (Table, Column, ManyToOne, etc.). I'm trying to figure out why I need to explicitely use each annotation class instead of them being automatically recognized (shouldn't use DoctrineORMMapping grant me access to all the classes within that namespace?).

                  因此,我尝试了使用 DoctrineORMMapping 作为 ORM 并使用 ORM 在我的所有注释前加上.例如:@ORMEntity().Symfony2 验证器停止抱怨,但现在 Doctrine2 抱怨 Class EntityUser 不是有效实体或映射的超类. 我不知道为什么这种方法适用于验证器,而不适用于 Doctrine2.如果我运行控制台命令 doctrine:orm:info,则无法识别我的 User 实体.

                  So, I then tried use DoctrineORMMapping as ORM and prefacing all my annotations with ORM. Ex: @ORMEntity(). The Symfony2 validator stops complaining, but now Doctrine2 complains that Class EntityUser is not a valid entity or mapped super class. I have no idea why this method works for the Validator, but not Doctrine2. If I run the console command doctrine:orm:info, my User entity is not recognized.

                  因为这是一个 CodeIgniter 应用程序,所以我正在自动加载 Symfony2 和 Doctrine2 库.我的自动加载代码如下:

                  Because this is a CodeIgniter app, I'm autoloading the Symfony2 and Doctrine2 libraries. My autoload code is as follows:

                  # Symfony2 ClassLoader component
                  require_once __DIR__ . '/application/libraries/symfony/src/Symfony/Component/ClassLoader/UniversalClassLoader.php';
                  $loader = new SymfonyComponentClassLoaderUniversalClassLoader();
                  $loader->register();
                  $loader->registerNamespace('Symfony', __DIR__ . '/application/libraries/symfony/src');
                  $loader->registerNamespace('Doctrine', __DIR__ . '/application/libraries/doctrine/lib');
                  
                  # Doctrine2 
                  require_once __DIR__ . '/application/libraries/doctrine/lib/Doctrine/Common/Annotations/AnnotationRegistry.php';
                  use DoctrineCommonAnnotationsAnnotationRegistry;
                  AnnotationRegistry::registerLoader(function($class) use ($loader) {
                      $loader->loadClass($class);
                      $classExists = class_exists($class, false);
                      return $classExists;
                  });
                  AnnotationRegistry::registerFile(__DIR__ . '/application/libraries/doctrine/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php');
                  

                  我不在乎是否必须以 ORM 开头所有内容,我只想找到一个 Symfony2 Validator 和 Doctrine2 都可以使用的解决方案.有什么想法吗?

                  I don't care if I have to preface everything with ORM or not, I just want to find a solution that the Symfony2 Validator and Doctrine2 will both work with. Any ideas?

                  推荐答案

                  我在使用 Silex、Doctrine2 和 Symfony-Validator 时遇到了类似的问题.

                  I had a similar issue when using Silex, Doctrine2 and the Symfony-Validator.

                  解决方案是避免使用 SimpleAnnotationsReader 而是使用普通的 AnnotationReader(查看 DoctrineORMConfiguration::newDefaultAnnotationDriver).然后你可以用 ORM 为每个实体做序(当然,在每个实体中插入 use DoctrineORMMapping as ORM;).

                  The solution was to avoid using the SimpleAnnotationsReader and instead using the normal AnnotationReader (have a look at DoctrineORMConfiguration::newDefaultAnnotationDriver). You can then preface every entity with ORM (and of course inserting use DoctrineORMMapping as ORM; in every entity).

                  这篇关于导入注释时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                    • <legend id='ETq1c'><style id='ETq1c'><dir id='ETq1c'><q id='ETq1c'></q></dir></style></legend>

                        <small id='ETq1c'></small><noframes id='ETq1c'>

                        <tfoot id='ETq1c'></tfoot>
                        <i id='ETq1c'><tr id='ETq1c'><dt id='ETq1c'><q id='ETq1c'><span id='ETq1c'><b id='ETq1c'><form id='ETq1c'><ins id='ETq1c'></ins><ul id='ETq1c'></ul><sub id='ETq1c'></sub></form><legend id='ETq1c'></legend><bdo id='ETq1c'><pre id='ETq1c'><center id='ETq1c'></center></pre></bdo></b><th id='ETq1c'></th></span></q></dt></tr></i><div id='ETq1c'><tfoot id='ETq1c'></tfoot><dl id='ETq1c'><fieldset id='ETq1c'></fieldset></dl></div>

                          <bdo id='ETq1c'></bdo><ul id='ETq1c'></ul>
                              <tbody id='ETq1c'></tbody>