Symfony 2异常:在控制器中找不到类 [英] Symfony 2 Exception: Class not found in Controller

查看:319
本文介绍了Symfony 2异常:在控制器中找不到类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我试图在我的自定义动作下一步中创建类Engineering_Detail的新对象,问题是,即使我使用使用... 。\Entity\Engineering_Detail它会抛出那个错误我在做 $ detail = new Engineering_Detail();

Okay so, I'm trying to create a new object of the class "Engineering_Detail" inside my custom action "next", the problem is, even though I'm using "Use ....\Entity\Engineering_Detail" it throws that error on the line i'm doing $detail = new Engineering_Detail();


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

FatalErrorException: Error: Class 'Mine\Bundle\EngMgmtBundle\Entity\Engineering_Detail' not found in C:\xampp\htdocs\EngMgmt\src\Mine\Bundle\EngMgmtBundle\Controller\EngineeringController.php line 403

行403是 $ detail = new Engineering_Detail();

这里是重要的控制器位:

Here's the important controller bits:

<?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()
             );
    }

我已经选中和验证,但一切似乎好。该实体是使用SF2控制台中的工具生成的。

I already checked this and verified but everything seems okay. That entity was generated using the tools inside the SF2 console. What am I doing wrong?

编辑:

Note: I have already deleted cache

strong>

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

Tried with all other entities, using the same namespace and just changing the entity's name, and declaring objects, it seems the issue it's just with the entities with the _ in their name.

推荐答案

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

Fixed by deleting the _ in the entity name and changing all of its occurrences

这篇关于Symfony 2异常:在控制器中找不到类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆