【问题标题】:The autoloader expected class自动加载器预期的类
【发布时间】:2017-08-14 12:35:23
【问题描述】:

我在 symfony 中为标签创建了代码,但我有这个错误:

自动加载器预期类“Tag\TagBundle\Form\Types\TagsType”将在文件“/var/www/html/TagProject/vendor/composer/../../src/Tag/TagBundle/Form”中定义/Types/TagsType.php”。找到文件但类不在其中,类名或命名空间可能有错字。

TagsType.php:

<?php 

    namespace Tag\TagBundle\Form\Types;

    use Symfony\Component\Form\AbstractType;
    use Symfony\Component\Form\Extension\Core\Type\TextType;
    use Tag\TagBundle\Form\DataTransformer\TagsTransformer;
    use Symfony\Bridge\Doctrine\Form\DataTransformer\CollectionArrayTransformer;
    use Symfony\Component\Form\FormBuilderInterface;

    class TagsTypes extends AbstractType {

        public function buildForm(FormBuilderInterface $builder, array $options){
            $builder
                    ->addModelTransformer(new CollectionArrayTransformer(),true)
                    ->addModelTransformer(new TagsTransformer(),true);
        }

        public function getParent(){
            return TextType::class;
        }

    }
}

TagsTransformer.php:

<?php 

    namespace Tag\TagBundle\Form\DataTransformer;

    use Symfony\Component\Form\DataTransformerInterface;

    class tagsTransformer implements DataTransformerInterface {

        public function transform($value){
            dump($value);
            return "";
        }
        public function reverseTransform($value){

        }
    }

PostType.php:

<?php

    namespace AppBundle\Form;

    use Symfony\Component\Form\AbstractType;
    use Symfony\Component\Form\FormBuilderInterface;
    use Symfony\Component\OptionsResolver\OptionsResolver;
    use Tag\TagBundle\Form\Types\TagsType;

    class PostType extends AbstractType
    {
        /**
         * {@inheritdoc}
         */
        public function buildForm(FormBuilderInterface $builder, array $options)
        {
            $builder->add('name')
                    ->add('content')
                    ->add('tags',TagsType::class);
        }

        /**
         * {@inheritdoc}
         */
        public function configureOptions(OptionsResolver $resolver)
        {
            $resolver->setDefaults(array(
                'data_class' => 'AppBundle\Entity\Post'
            ));
        }

        /**
         * {@inheritdoc}
         */
        public function getBlockPrefix()
        {
            return 'appbundle_post';
        }
    }

【问题讨论】:

  • 你能发现问题吗?类标签类型 ...
  • 乳清@cerad !!!
  • 类名拼写错误:TagsTypes => TagsType
  • 感谢我的朋友@yceruto
  • 错误本身说The file was found but the class was not in it, the class name or namespace probably has a typo.

标签: php forms entity-framework symfony


【解决方案1】:

您的错误是命名class

你有 TagsType.php 是 php 文件,你的类名是 TagsTypes:

您必须更改class 名称:

class TagsTypes

class TagsType

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-28
    • 2013-06-02
    • 1970-01-01
    相关资源
    最近更新 更多