在composer的自动加载器中不存在的类

时间:2017-09-17 06:32:19

标签: php symfony

我在symfony中编写了默认控制器和一个任务类。我的问题是它抛出了与自动加载器编写器相关的错误。

The autoloader expected class "AppBundle\Entity\Task" to be defined in file "C:\wamp64\www\Form1_Symfony\vendor\composer/../../src/AppBundle\Entity\Task.php". The file was found but the class was not in it, the class name or namespace probably has a typo

我该如何解决?

defaultController.php,它使用任务类并拥有路由,最后创建一个表单并返回它     

use AppBundle\Entity\Task;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Response;

class DefaultController extends Controller
{
/**
 * @Route("/lk")
 */
public function newAction(Request $request)
{
    // create a task and give it some dummy data for this example
    $task = new Task();
    $task->setTask('Write a blog post');
    $task->setDueDate(new \DateTime('tomorrow'));

    $form = $this->createFormBuilder($task)
        ->add('task', TextType::class)
        ->add('dueDate', DateType::class)
        ->add('save', SubmitType::class, array('label' => 'Create Post'))
        ->getForm();

    return $this->render('default/new.html.twig', array(
        'form' => $form->createView(),
    ));
}
}

返回任务和时间的Task.php,用于稍后创建。

<?php
namespace AppBundle\Entity\Task;
class Task
{
protected $task;
protected $date;

public function getTask(){
    return $this->task;
}
public function getDate(){
    return $this->date;
}
}

1 个答案:

答案 0 :(得分:1)

namespace AppBundle\Entity\Task;
class Task

定义类AppBundle\Entity\Task\Task。您的名称空间应为AppBundle\Entity