对不起,我读了很多关于这个错误的帖子,但仍然找不到我失败的地方。
错误说明:
The autoloader expected class "TP\MainBundle\Form\ContactoType" to be defined in file "C:\xampp\htdocs\TP/src\TP\MainBundle\Form\ContactoType.php". The file was found but the class was not in it, the class name or namespace probably has a typo.
我的routing.yml是
contacto_new:
pattern: /new
defaults: { _controller: TPMainBundle:default:new }
我的文件'Contacto.php'位于TP / src / TP / MainBundle / Entity下,第一行代码为:
<?php
namespace TP\MainBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
我的'ContactoType.php'位于TP / src / TP / MainBundle / Form / ContactoType.php
它的代码是:
<?php
namespace Tp\MainBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
class CursoType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('name');
$builder->add('email');
$builder->add('message'); }
public function getName()
{
return 'contacto_form';
}
}
我在DefaultController中的Action是:
public function newAction()
{
$contacto = new Contacto();
$form = $this->createForm(new ContactoType(), $contacto);
return $this->render('TPMainBundle:Default:new.html.twig', array(
'form' => $form->createView(),
));
}
}
我无法理解错误的位置
答案 0 :(得分:0)
您的ContactoType.php应该包含相同的命名类,而不是它具有CursoType类。