2017-02-01 41 views
0

我得到這個錯誤,因爲這個,我也瘋了。 我正在使用Symfony 3.2.2框架和Autoloader聲稱找到該文件,但該類不在其中,類名或命名空間可能有錯字。Symfony,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){ 

    } 
} 
+0

預計什麼樣的類? –

+0

要在文件「/home/huseyinocal/bookkeeper/vendor/composer/../../src/Bookkeeper/ManagerBundle/Form/BookType.php」中定義的自動加載器預期類「Bookkeeper \ ManagerBundle \ Form \ BookType」。該文件已找到,但該類不在其中,類名或命名空間可能有拼寫錯誤。 –

回答

0

你寫的命名空間Bookkeeeper\ManagerBundle\Form;而不是命名空間Bookkeeper\ManagerBundle\Form; (注意在你寫的東西中的額外的東西)

<?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'; 
    } 



} 
+0

我的文件被稱爲BookController.php而不是Bookkeeper.Controller.php。我剛纔寫了一些錯誤並編輯了它。 –

+0

我編輯了我的回答,並附上你對@u_mulder的回覆評論 – OlivierC

+0

非常感謝你的回覆。我無疑是很複雜的。 –

相關問題