Symfony 2异常:在Controller中找不到类

时间:2013-11-29 21:11:19

标签: class exception symfony

好的,我正在尝试创建一个新类的对象" Engineering_Detail"在我的自定义操作" next"中,问题是,即使我使用"Use ....\Entity\Engineering_Detail",它会在我执行$detail = new Engineering_Detail();的行上抛出该错误

  

FatalErrorException:错误:Class' Mine \ Bundle \ EngMgmtBundle \ Entity \ Engineering_Detail'在C:\ xampp \ htdocs \ EngMgmt \ src \ Mine \ Bundle \ EngMgmtBundle \ Controller \ EngineeringController.php第403行中找不到

第403行是$detail = new Engineering_Detail();

这是重要的控制器位:

<?php

namespace Mine\Bundle\EngMgmtBundle\Controller;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Mine\Bundle\EngMgmtBundle\Entity\Engineering;
use Mine\Bundle\EngMgmtBundle\Form\EngineeringType;
use Mine\Bundle\EngMgmtBundle\Entity\Engineering_Detail;
/**
 * Engineering controller.
 *
 * @Route("/engineering")
 */
class EngineeringController extends Controller
{
/**
     * Updates a Engineering entity.
     *
     * @Route("/{id}/next/", name="engineering_next")
     * @Method("POST")
     * @Template("MineEngMgmtBundle:Engineering:update.html.twig")
     */
   public function nextAction(Request $request, $id){
        $em = $this->getDoctrine()->getManager();
        $entity = $em->getRepository('MineEngMgmtBundle:Engineering')->find($id);

        $current_form = $this->getForm($entity->getStatus()->getInternalOrder()); 
        $current_form->handleRequest($request);

        $detail = new Engineering_Detail();

        if ($current_form->isValid()) {

            $data = $current_form->getData();

            switch ($entity->getStatus()->getInternalOrder()){

                case 1:

                 if (($data["sitesurvey"]) == 'n'){
                     $status = $em->getRepository('MineEngMgmtBundle:Status')->findBy(array('internalOrder' => 8));
                     $next_form = $this->getForm($entity->getStatus()->getInternalOrder());
                }else{
                     $status = $em->getRepository('MineEngMgmtBundle:Status')->find(2);
                     $next_form = $this->getForm($entity->getStatus()->getInternalOrder());
                }    

                    break;

                default:
                     $status = $em->getRepository('MineEngMgmtBundle:Status')->findBy(array('internalOrder' => $entity->getStatus()->getInternalOrder()+1));
                     $next_form = $this->getForm($entity->getStatus()->getInternalOrder());
                    break;
            }

                     $detail->setEngineering($entity);
                     $detail->setFromStatus($entity->getStatus());
                     $detail->setToStatus($status);
                     $detail->setUpdatedDate(new \DateTime());
                     $detail->setUser($this->get('security.context')->getToken()->getUser());
                     $detail->setComments($data["comments"]);
                     $entity->setStatus($status);
                     $em->flush();
        }
            return array(
                        'entity' => $entity,
                        'form'   => $next_form->createView()
             );
    }

我已经检查过this并已经过验证,但一切似乎都没问题。该实体是使用SF2控制台内的工具生成的。我做错了什么?

注意:我已经删除了缓存

修改

与所有其他实体一起尝试,使用相同的命名空间,只更改实体的名称,并声明对象,似乎问题只是与 _ 以他们的名义。

2 个答案:

答案 0 :(得分:4)

您正在混合PSR命名空间和类命名。无法找到它的原因是因为您的实体应该被称为EngineeringDetail,以便自动装载器正确找到。

答案 1 :(得分:0)

通过删除实体名称中的_并更改其所有出现次数来修复