【问题标题】:Class_parents error in Entity/Repository实体/存储库中的 Class_parents 错误
【发布时间】:2012-07-20 10:40:39
【问题描述】:

在我正在开发且工作正常的捆绑包中,我添加了一项新功能,其中涉及向实体添加存储库。现在,当我执行新添加的方法时,出现以下错误:

警告:class_parents() [function.class-parents]:类 CmsPages 不存在,无法加载到 /Applications/MAMP/htdocs/symfony-standard-2.1/vendor/doctrine/common/lib/Doctrine/ Common/Persistence/Mapping/RuntimeReflectionService.php 第 40 行

新增代码为:

控制器:

/**
 * Returns an json formated tree
 * 
 * @Route("/getTree", name="admin_cmsPages_getTree", options={"expose"=true})
 */
public function getTreeAction()
{

    $em = $this->getDoctrine()->getManager();
    $tree = $em->getRepository('CmsPages')->loadTree();


    $response = new Response(json_encode( $tree ));
    $response->headers->set('Content-Type', 'application/json');

    return $response;
}

存储库:

namespace Yanic\CmsBundle\Entity;

use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\NoResultException;

class CmsPagesRepository extends EntityRepository
{
    public function loadTree()
    {
        $q = $this
            ->createQueryBuilder('p')
            ->select('p')
            ->orderBy( 'p.lft' )
            ->getQuery()
            ;

        return $q->getArrayResult();
    }
}

这就是所有的变化......如果需要更多代码来澄清,我会发布它。

那么谁能告诉我我做错了什么?我在 SO 和 Google 上都找不到任何东西。

提前致谢

【问题讨论】:

标签: php doctrine-orm symfony-2.1


【解决方案1】:

我自己也发现了错误...行

$tree = $em->getRepository('CmsPages')->loadTree();

必须是

$tree = $em->getRepository('CmsBundle:CmsPages')->loadTree();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-04
    • 2023-03-18
    • 2012-07-26
    • 1970-01-01
    • 1970-01-01
    • 2021-07-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多