找不到控制器:服务“ AppBundle / Controller / TestController.php”不存在

时间:2019-12-23 06:58:45

标签: php symfony debian

我收到错误消息Controller not found: service "AppBundle / Controller / TestController.php" does not exist 但我不知道如何调试它。有人可以帮帮我吗 !? 错误是否可能是由于布线引起的还是其他原因! 我只想澄清一下,我使用的是Symfony 3.4。

这是TestController.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;

/**
* Description of TestController
*
* @author m.andriamil
* @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,
    ]);
}

}`

先谢谢您

0 个答案:

没有答案