duanfu4446 2017-08-14 12:35
浏览 59
已采纳

自动加载器预期类

I created code for tags in symfony but I have this bug:

The autoloader expected class "Tag\TagBundle\Form\Types\TagsType" to be defined in file "/var/www/html/TagProject/vendor/composer/../../src/Tag/TagBundle/Form/Types/TagsType.php". The file was found but the class was not in it, the class name or namespace probably has a typo.

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';
        }
    }
  • 写回答

1条回答 默认 最新

  • dongsha9208 2017-08-14 13:51
    关注

    Your error is naming class.

    You have TagsType.php is php file and your class name is TagsTypes:

    You have to change class name:

    class TagsTypes

    to

    class TagsType

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 国外网络搭建,有偿交流
  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?