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

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

问题描述

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


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


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



这是重要的控制器位:

 <?php 

命名空间Mine\Bundle\EngMgmtBundle\Controller;

使用Symfony\Component\HttpFoundation\Request;
使用Symfony\Bundle\FrameworkBundle\Controller\Controller;
使用Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
使用Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
使用Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
使用Mine\Bundle\EngMgmtBundle\Entity\Engineering;
使用Mine\Bundle\EngMgmtBundle\Form\EngineeringType;
使用Mine\Bundle\EngMgmtBundle\Entity\Engineering_Detail;
/ **
*工程控制器。
*
* @Route(/ engineering)
* /
class EngineeringController扩展Controller
{
/ **
*更新一个工程实体。
*
* @Route(/ {id} / next /,name =engineering_next)
* @Method(POST)
* @Template( B
$ /
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()){

案例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;

默认值:
$ 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();
}
返回数组(
'entity'=> $ entity,
'form'=> $ next_form-> createView()
);
}

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



注意:我已经删除缓存



编辑: strong>



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

解决方案

通过删除实体名称中的_并更改其所有事件修正


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: Error: Class 'Mine\Bundle\EngMgmtBundle\Entity\Engineering_Detail' not found in C:\xampp\htdocs\EngMgmt\src\Mine\Bundle\EngMgmtBundle\Controller\EngineeringController.php line 403

The line 403 is $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()
             );
    }

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

EDIT:

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异常:在Controller中找不到类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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