好的,我正在尝试在我的自定义操作"next“中创建类"Engineering_Detail”的一个新对象,问题是,即使我使用的是"Use ....\Entity\Engineering_Detail",它也会在我执行$detail = new Engineering_Detail();的行中抛出这个错误
错误:'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控制台内的工具生成的。我做错了什么?
注意:我已经删除了缓存。
编辑:
与所有其他实体一起尝试,使用相同的命名空间,只更改实体的名称,并声明对象,这似乎是一个问题--它只是与名称中有_的实体有关。
发布于 2013-11-30 20:25:48
通过删除实体名称中的_并更改其所有出现情况来修正
发布于 2013-11-29 22:47:53
您正在混合PSR名称空间和类命名。之所以找不到它,是因为您的实体应该被称为EngineeringDetail,才能被自动加载器正确地找到。
https://stackoverflow.com/questions/20293411
复制相似问题