• <legend id='TpFdo'><style id='TpFdo'><dir id='TpFdo'><q id='TpFdo'></q></dir></style></legend>
      <bdo id='TpFdo'></bdo><ul id='TpFdo'></ul>

  • <tfoot id='TpFdo'></tfoot>

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

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

        Symfony2 Doctrine Custom Repository Class [Semantical Error]

        时间:2023-08-18
        <tfoot id='cEXUI'></tfoot>
          <bdo id='cEXUI'></bdo><ul id='cEXUI'></ul>

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

                  <tbody id='cEXUI'></tbody>
                <i id='cEXUI'><tr id='cEXUI'><dt id='cEXUI'><q id='cEXUI'><span id='cEXUI'><b id='cEXUI'><form id='cEXUI'><ins id='cEXUI'></ins><ul id='cEXUI'></ul><sub id='cEXUI'></sub></form><legend id='cEXUI'></legend><bdo id='cEXUI'><pre id='cEXUI'><center id='cEXUI'></center></pre></bdo></b><th id='cEXUI'></th></span></q></dt></tr></i><div id='cEXUI'><tfoot id='cEXUI'></tfoot><dl id='cEXUI'><fieldset id='cEXUI'></fieldset></dl></div>
                  <legend id='cEXUI'><style id='cEXUI'><dir id='cEXUI'><q id='cEXUI'></q></dir></style></legend>
                1. 本文介绍了Symfony2 Doctrine Custom Repository Class [Semantical Error] line 0, col 14 near 'Project p': Error: Class 'Project' is not defined的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我是 Symfony 2 和 Doctrine 的新手,有一个简单的问题:

                  I'm really new in Symfony 2 and Doctrine, and have a simple problem:

                  我的存储库中有一段非常简单的代码:

                  There is a pretty simple code in my repository:

                  <?php
                  
                  namespace BakeryITBakeryBundleEntity;
                  
                  use DoctrineORMEntityRepository;
                  
                  class ProjectRepository extends EntityRepository
                  {
                      public function findHistory(){
                          return $this->getEntityManager()
                          ->createQueryBuilder()
                          ->select('p')
                          ->from('Project','p')
                          ->getQuery()
                          ->getResult();
                      }
                  }
                  

                  我的控制器中有两个简单的函数:

                  And two simple functions in my controller:

                  <?php
                  
                  namespace BakeryITBakeryBundleController;
                  
                  /*
                  ...
                  */
                  
                  class ProjectController extends Controller
                  {
                      public function indexAction()
                      {
                          return $this->index('Project', 'findHistory');
                      }
                  }
                  

                  控制器看起来像这样:

                  public function index($entity, $query = 'findAll')
                  {
                      $repository = $this->getDoctrine()
                          ->getRepository('BakeryBundle:'.$entity);
                  
                      $data = $repository->$query();
                  
                      return $this->render('BakeryBundle:'.$entity.':index.html.twig',
                      array('data' => $data));
                  }
                  

                  此代码向我抛出语义错误 [语义错误] 行 0,'Project p' 附近的第 14 列:错误:未定义类 'Project'.

                  This code throw me the Semantical Error [Semantical Error] line 0, col 14 near 'Project p': Error: Class 'Project' is not defined.

                  另一方面,如果我更改存储库中的这一行,则一切正常:

                  On the other hand everything works perfectly if I change this line in my repository:

                  ->from('Project','p')
                  

                  ->from('BakeryITBakeryBundleEntityProject','p')
                  

                  我不知道为什么这个例子在第一种情况下不起作用.我的 BakeryITBakeryBundleEntityProject 中的命名空间是这样设置的:

                  I don't know why this example doesn't work in the first case. Namespace in my BakeryITBakeryBundleEntityProject is set in this way:

                  namespace BakeryITBakeryBundleEntity;
                  
                  use DoctrineORMMapping as ORM;
                  
                  /**
                   * Project
                   *
                   * @ORMTable()
                   * @ORMEntity(repositoryClass="BakeryITBakeryBundleEntityProjectRepository")
                   */
                  class Project
                  {
                  /*
                  ..
                  */
                  }
                  

                  推荐答案

                  为了使用简短形式,您还需要提供包名称.这是根据供应商和捆绑包名称构造的.在你的情况下,它会是这样的:

                  In order to use the short form, you'll need to provide the bundle name too. This is constructed from the vendor and bundle name. In your case it would be something like:

                  from('BakeryITBakeryBundle:Project')
                  

                  有关捆绑包的更多信息,请参阅以下链接:

                  See the following link for more information on bundles:

                  http://symfony.com/doc/current/cookbook/bundles/best_practices.html

                  这篇关于Symfony2 Doctrine Custom Repository Class [Semantical Error] line 0, col 14 near 'Project p': Error: Class 'Project' is not defined的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Doctrine2 ManyToMany 不执行侦听器事件 下一篇:当我尝试进行 YAML 映射时出现 Doctrine 2.0 ReflectionException

                  相关文章

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

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

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