Php Symfony,自动加载器类不在其中
我犯了这个错误,我也因此发疯了。 我使用的是Symfony 3.2.2 framework,Autoloader声称找到了文件,但类不在其中,类名或命名空间可能有输入错误。 堆栈跟踪Php Symfony,自动加载器类不在其中,php,symfony,Php,Symfony,我犯了这个错误,我也因此发疯了。 我使用的是Symfony 3.2.2 framework,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 "/".', $
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';
}
}
您编写了名称空间Bookkeeeper\ManagerBundle\Form
;而不是名称空间簿记员\ManagerBundle\Form
;(请注意您所写内容中的额外e)
需要什么类?自动加载程序需要在文件“/home/huseyinocal/Bookkeeper/vendor/composer/./../src/Bookkeeper/ManagerBundle/Form/BookType.php”中定义类“Bookkeeper\ManagerBundle\Form\BookType”。找到了该文件,但该类不在其中,类名或命名空间可能有输入错误。我的文件名为BookController.php,而不是Bookkeeper.Controller.php。我不久前写错了,并对其进行了编辑。我用您对@u_Mulder的回复注释编辑了我的答案。非常感谢您的帮助。毫无疑问,我很复杂。
<?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){
}
}
<?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';
}
}