未找到控制器:服务“;AppBundle/Controller/TestController.php“;不存在
我发现错误未找到控制器:服务“;AppBundle/Controller/TestController.php“;不存在,php,symfony,debian,Php,Symfony,Debian,我发现错误找不到控制器:服务“AppBundle/Controller/TestController.php”不存在 但我不知道如何调试它。有人能帮帮我吗!? 可能是路由错误还是其他原因造成的!? 我只是想澄清一下,我使用的是Symfony 3.4 下面是TestController.php代码的摘录 <?php namespace AppBundle\Controller; use AppBundle\Entity\Task; use AppBundle\Form\TaskType;
找不到控制器:服务“AppBundle/Controller/TestController.php”不存在
但我不知道如何调试它。有人能帮帮我吗!?
可能是路由错误还是其他原因造成的!?
我只是想澄清一下,我使用的是Symfony 3.4
下面是TestController.php代码的摘录
<?php
namespace AppBundle\Controller;
use AppBundle\Entity\Task;
use AppBundle\Form\TaskType;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("test/form-test")
*/
class TestController extends Controller
{
/**
* @Route("/", name="test")
*/
public function newAction(Request $request)
{
// creates a task and gives it some dummy data for this example
$task = new Task();
$task->setTask('Write a blog post');
$task->setDueDate(new \DateTime('tomorrow'));
$form = $this->get('form.factory')->createNamed('addTask', TaskType::class, $task);
$form->handleRequest($request);
$validator = $this->get('validator');
$errors = $validator->validate($form);
if (count($editErrors) > 0) {
$errorsString = (string)$editErrors;
return new Response($errorsString);
}
echo('------------------------------------------------------------------------' . $form->isSubmitted() . ' && ' . $form->isValid());
if ($form->isSubmitted() && $form->isValid()) {
// $form->getData() holds the submitted values
// but, the original `$task` variable has also been updated
$task = $form->getData();
// ... perform some action, such as saving the task to the database
// for example, if Task is a Doctrine entity, save it!
// $entityManager = $this->getDoctrine()->getManager();
// $entityManager->persist($task);
// $entityManager->flush();
return new Response('<h1>-----------------------------------------------------------------------------------OK</h1>');
}
return $this->render('default/index.html.twig', [
'form' => $form->createView(),
'errors' => $errors,
]);
}
}
你能给这个问题添加一些相关的代码吗,是什么添加的代码触发了错误?TestController存在吗?你试着做什么来调试自己?已经完成了。你的意思是你解决了它?还没有。。。但我在问题中添加了代码。我就是这么做的:我明白了!因此,当您尝试访问“/test/formtest”时会发生错误?此控制器是否放置在控制器目录中?php-bin/console-debug:container的输出是什么,您能在那里找到控制器服务吗?