“传递给Symfony \ Bridge \ Twig \ Extension \ TranslationExtension :: trans()的参数1必须为字符串类型,给定null”

时间:2020-04-18 20:42:47

标签: vichuploaderbundle

我无法通过vichUploader上传PDF文件,出现此错误error,这是错误line 214 中给出的行 这是我的实体Candidat:

vich_uploader:
db_driver: orm
mappings:
    featured_files:
        uri_prefix: '%app.path.featured_files%'
        upload_destination: '%kernel.project_dir%/public%app.path.featured_files%'

    cv_files:
        uri_prefix: /pdf
        upload_destination:  '%kernel.project_dir%/public/pdf'

这是vichuploader.yaml

    <?php

namespace App\Form;

use App\Entity\Candidat;
use App\Entity\Entreprise;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\TelType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\File;
use Symfony\Component\Validator\Constraints\IsTrue;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Vich\UploaderBundle\Form\Type\VichFileType;

class RegistrationFormType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('email')
            ->add('agreeTerms', CheckboxType::class, [
                'mapped' => false,
                'constraints' => [
                    new IsTrue([
                        'message' => 'You should agree to our terms.',
                    ]),
                ],
            ])
            ->add('plainPassword', PasswordType::class, [
                // instead of being set onto the object directly,
                // this is read and encoded in the controller
                'mapped' => false,
                'constraints' => [
                    new NotBlank([
                        'message' => 'Please enter a password',
                    ]),
                    new Length([
                        'min' => 6,
                        'minMessage' => 'Your password should be at least {{ limit }} characters',
                        // max length allowed by Symfony for security reasons
                        'max' => 4096,
                    ]),
                ],
            ])

            ->add('nom',TextType::class)
            ->add('cvFile',VichFileType::class)
            ->add('prenom',TextType::class)
            ->add('civilite',ChoiceType::class,[
                'choices'=>[
                    'madame'=>'madame',
                    'monsieur'=>'mr'
                ]
            ])
            ->add('sexe',ChoiceType::class,[
                'choices'=>[
                    'femme'=>'f',
                    'homme'=>'h'
                ]
            ])


        ;
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            'data_class' => Candidat::class,
        ]);
    }
}

这是注册表格:

use App\Http\Controllers\AnnonceController;
Route::get('/annonces', function(AnnonceController $ctl) {
    return view('annonces', ['data' => $ctl->annonceAffiche()]);
});

我试图通过FileType更改VichFileTyoe,并且没有错误,所以我不知道错误的出处(因为我已经在easyAdmin模板中使用此捆绑包来上传图像,并且可以工作)。我不知道如何修复它或它来自哪里。

0 个答案:

没有答案