,我得到了这个错误,我也因为这个而变得疯狂。我使用Symfony 3.2.2框架,Autoloader声称找到了该文件,但类不在其中,类名或命名空间可能有一个错误。
堆栈跟踪
throw new \RuntimeException(sprintf('Trying to autoload a class with an invalid name "%s". Be careful that the namespace separator is "\" in PHP, not "/".', $class));
}
throw new \RuntimeException(sprintf('The autoloader expected class "%s" to be defined in file "%s". The file was found but the class was not in it, the class name or namespace probably has a typo.', $class, $file));
}
if (self::$caseCheck) {
$real = explode('\\', $class.strrchr($file, '.'));
这是我的BookType.php;
<?php
namespace Bookkeeeper\ManagerBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class BookType extends AbstractType{
public function buildForm(FormBuilderInterface $builder, array $options){
$builder->add('title')->add('description')->add('pages');
}
public function setDefaultOptions(OptionsResolverInterface $resolver){
$resolver->setDefault(array('data_class'=>'Bookkeeeper\ManagerBundle\Entity\Book'));
}
public function getName(){
return 'bookkeeeper_managerbundle_book';
}
}
**这是我的BookController.php文件**
<?php
namespace Bookkeeper\ManagerBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Bookkeeper\ManagerBundle\Entity\Book;
use Bookkeeper\ManagerBundle\Form\BookType;
class BookController extends Controller
{
public function indexAction(){
return $this->render('BookkeeperManagerBundle:Book:index.html.twig');
}
public function showAction($id){
return $this->render('BookkeeperManagerBundle:Book:show.html.twig');
}
public function newAction(){
$book = new Book();
$form = $this->createForm(new BookType(), $book, array (
'action' =>$this->generateUrl('book_create'),
'method'=> 'POST'
));
$form->add('submit' , 'submit' , array('label' => 'Create Book'));
return $this->render('BookkeeperManagerBundle:Book:new.html.twig', array(
'form'=>$form->createView()
));
}
public function createAction(Request $request){
}
public function editAction($id){
return $this->render('BookkeeperManagerBundle:Book:edit.html.twig');
}
public function updateAction(Request $request, $id){
}
public function deleteAction(Request $request, $id){
}
}
发布于 2017-02-01 12:24:50
您编写了名称空间Bookkeeeper\ManagerBundle\Form
;而不是名称空间Bookkeeper\ManagerBundle\Form
;(请注意您所写内容中的额外e)
<?php
namespace Bookkeeper\ManagerBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class BookType extends AbstractType{
public function buildForm(FormBuilderInterface $builder, array $options){
$builder->add('title')->add('description')->add('pages');
}
public function setDefaultOptions(OptionsResolverInterface $resolver){
$resolver->setDefault(array('data_class'=>'Bookkeeeper\ManagerBundle\Entity\Book'));
}
public function getName(){
return 'bookkeeeper_managerbundle_book';
}
}
https://stackoverflow.com/questions/41979695
复制相似问题