我从现有实体创建了一个CRUD,一切都很顺利,直到我看到结果,我收到以下错误:
(使用Symfony 3)
尝试从命名空间“Symfony \ Component \ Security \ Acl \ Voter”加载类“FieldVote”。 您是否忘记了另一个命名空间的“use”语句? 500内部服务器错误 - ClassNotFoundException
我不知道如何处理这个问题,因为似乎没有人遇到过这个问题,也没有找到导致问题的原因。
无论如何,这是我的实体和我的控制器的片段:
MissionBundle.php
<?php
namespace MissionBundle\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 MissionBundle\Entity\Mission;
use MissionBundle\Form\MissionType;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
/**
* Mission controller.
*
* @Route("/mission")
*/
class MissionController extends Controller
{
/**
* Lists all Mission entities.
*
* @Route("/", name="mission_index")
* @Method("GET")
*/
public function indexAction()
{
$em = $this->getDoctrine()->getManager();
$missions = $em->getRepository('MissionBundle:Mission')->findAll();
return $this->render('mission/index.html.twig', array(
'missions' => $missions,
));
}
/**
* Creates a new Mission entity.
*
* @Route("/new", name="mission_new")
* @Security("has_role('ROLE_RECRUTEUR') or has_role('ROLE_RESPONSABLE')")
* @Method({"GET", "POST"})
*/
public function newAction(Request $request)
{
$mission = new Mission();
$form = $this->createForm('MissionBundle\Form\MissionType', $mission);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($mission);
$em->flush();
return $this->redirectToRoute('mission_show', array('id' => $mission->getId()));
}
return $this->render('mission/new.html.twig', array(
'mission' => $mission,
'form' => $form->createView(),
));
}
/**
* Finds and displays a Mission entity.
*
* @Route("/{id}", name="mission_show")
* @Method("GET")
*/
public function showAction(Mission $mission)
{
$deleteForm = $this->createDeleteForm($mission);
return $this->render('mission/show.html.twig', array(
'mission' => $mission,
'delete_form' => $deleteForm->createView(),
));
}
/**
* Displays a form to edit an existing Mission entity.
*
* @Route("/{id}/edit", name="mission_edit")
* @Security("has_role('ROLE_RECRUTEUR') or has_role('ROLE_RESPONSABLE')")
* @Method({"GET", "POST"})
*/
public function editAction(Request $request, Mission $mission)
{
$deleteForm = $this->createDeleteForm($mission);
$editForm = $this->createForm('MissionBundle\Form\MissionType', $mission);
$editForm->handleRequest($request);
if ($editForm->isSubmitted() && $editForm->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($mission);
$em->flush();
return $this->redirectToRoute('mission_edit', array('id' => $mission->getId()));
}
return $this->render('mission/edit.html.twig', array(
'mission' => $mission,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
}
/**
* Deletes a Mission entity.
* @Security("has_role('ROLE_RECRUTEUR') or has_role('ROLE_RESPONSABLE')")
* @Route("/{id}", name="mission_delete")
* @Method("DELETE")
*/
public function deleteAction(Request $request, Mission $mission)
{
$form = $this->createDeleteForm($mission);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->remove($mission);
$em->flush();
}
return $this->redirectToRoute('mission_index');
}
/**
* Creates a form to delete a Mission entity.
* @Security("has_role('ROLE_RECRUTEUR') or has_role('ROLE_RESPONSABLE')")
* @param Mission $mission The Mission entity
*
* @return \Symfony\Component\Form\Form The form
*/
private function createDeleteForm(Mission $mission)
{
return $this->createFormBuilder()
->setAction($this->generateUrl('mission_delete', array('id' => $mission->getId())))
->setMethod('DELETE')
->getForm()
;
}
}
Mission.php(实体)
<?php
// src/MissionBundle/Entity/Mission.php
namespace MissionBundle\Entity;
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity
*/
Class Mission{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string")
*/
private $intitule;
/**
* @ORM\Column(type="text")
*/
private $description;
/**
* @ORM\Column(type="datetime")
*/
private $dateDepot;
/**
* @ORM\Column(type="date")
*/
private $dateDebut;
/**
* @ORM\Column(type="date")
*/
private $dateFin;
/**
* @ORM\Column(type="boolean")
*/
private $visibilite;
/**
* @ORM\Column(type="boolean")
*/
private $isConnected;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set intitule
*
* @param string $intitule
*
* @return Mission
*/
public function setIntitule($intitule)
{
$this->intitule = $intitule;
return $this;
}
/**
* Get intitule
*
* @return string
*/
public function getIntitule()
{
return $this->intitule;
}
/**
* Set description
*
* @param string $description
*
* @return Mission
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Set dateDepot
*
* @param \DateTime $dateDepot
*
* @return Mission
*/
public function setDateDepot($dateDepot)
{
$this->dateDepot = $dateDepot;
return $this;
}
/**
* Get dateDepot
*
* @return \DateTime
*/
public function getDateDepot()
{
return $this->dateDepot;
}
/**
* Set dateDebut
*
* @param \DateTime $dateDebut
*
* @return Mission
*/
public function setDateDebut($dateDebut)
{
$this->dateDebut = $dateDebut;
return $this;
}
/**
* Get dateDebut
*
* @return \DateTime
*/
public function getDateDebut()
{
return $this->dateDebut;
}
/**
* Set dateFin
*
* @param \DateTime $dateFin
*
* @return Mission
*/
public function setDateFin($dateFin)
{
$this->dateFin = $dateFin;
return $this;
}
/**
* Get dateFin
*
* @return \DateTime
*/
public function getDateFin()
{
return $this->dateFin;
}
/**
* Set visibilite
*
* @param boolean $visibilite
*
* @return Mission
*/
public function setVisibilite($visibilite)
{
$this->visibilite = $visibilite;
return $this;
}
/**
* Get visibilite
*
* @return boolean
*/
public function getVisibilite()
{
return $this->visibilite;
}
/**
* Set isConnected
*
* @param boolean $isConnected
*
* @return Mission
*/
public function setIsConnected($isConnected)
{
$this->isConnected = $isConnected;
return $this;
}
/**
* Get isConnected
*
* @return boolean
*/
public function getIsConnected()
{
return $this->isConnected;
}
}
代码中没有提及投票或任何内容,因此我不知道加载FieldVote需要什么,或者是什么阻止它加载它。 有没有人有想法? 我必须确切地说,如果我继续执行任务/新任务,或任务/ {id}或其他什么,它的工作完全正常。
提前谢谢
答案 0 :(得分:0)
对我来说完全看起来像是一个symfony核心bug。分支3中的https://github.com/symfony/symfony/tree/master/src/Symfony/Component/Security中没有Acl目录。*
实际上,这个目录在2.7中被删除了,所以没有组件2.8应该使用它。也许你应该把它报告给SensioLabs。
要摆脱这个错误,您可以避免使用@Security Annotation,而是使用安全服务并在控制器内部测试授权:
if (false === $this->get('security.authorization_checker')->isGranted('ROLE_RECRUTEUR')) {
....
}