Я пытаюсь загрузить файл с помощью vichUploaderBundle, но в контроллере у меня нулевое значение в изображении атрибута (файл атрибута из vichuploaderBundle) .... Я пишу код из doc vichUploadBundle, но ошибка отображается в виде:
представление кода:
{% trans_default_domain 'FOSUserBundle' %}
<div class="justify-content-center row">
<div class="col-md-8">
{{ form_start(form, {'method': 'post', 'action': path('new_doctor'),'attr':{'enctype': 'multipart/form-data','id': 'regForm', 'novalidate': 'novalidate'}}) }}
<div class="form-group">
{{ form_widget(form.email,{ 'attr': {'class': 'form-control','placeholder': 'Email'}}) }}
{{ form_errors(form.email) }}
</div>
<div class="form-group">
{{ form_widget(form.firstName,{ 'attr': {'class': 'form-control','placeholder': 'firstName'}}) }}
{{ form_errors(form.firstName) }}
</div>
<div class="form-group">
{{ form_widget(form.lastName,{ 'attr': {'class': 'form-control','placeholder': 'lastName'}}) }}
{{ form_errors(form.lastName) }}
</div>
<div class="form-group">
{{ form_widget(form.region,{ 'attr': {'class': 'form-control','placeholder': 'Region'}}) }}
{{ form_errors(form.region) }}
</div>
<div class="form-group">
{{ form_widget(form.shortBio,{ 'attr': {'class': 'form-control','placeholder': 'shortBio'}}) }}
{{ form_errors(form.shortBio) }}
</div>
<div class="form-group">
{{ form_widget(form.streetAddress,{ 'attr': {'class': 'form-control','placeholder': 'streetAddress'}}) }}
{{ form_errors(form.streetAddress) }}
</div>
<div class="form-group">
{{ form_widget(form.postalCode,{ 'attr': {'class': 'form-control','placeholder': 'postalCode'}}) }}
{{ form_errors(form.postalCode) }}
</div>
<div class="form-group">
{{ form_widget(form.locality,{ 'attr': {'class': 'form-control','placeholder': 'locality'}}) }}
{{ form_errors(form.locality) }}
</div>
<div class="form-group">
{{ form_widget(form.country,{ 'attr': {'class': 'form-control','placeholder': 'country'}}) }}
{{ form_errors(form.country) }}
</div>
<div class="form-group">
{{ form_widget(form.speciality,{ 'attr': {'class': 'form-control','placeholder': 'speciality'}}) }}
{{ form_errors(form.speciality) }}
</div>
<div class="form-group">
{{ form_widget(form.picture,{ 'attr': {'class': 'form-control'}}) }}
{{ form_errors(form.picture) }}
</div>
<div class="form-group">
{{ form_widget(form.plainPassword.first,{ 'attr': {'class':'form-control' ,'placeholder': 'Password'} }) }}
{{ form_errors(form.plainPassword.first) }}
</div>
<div class="form-group">
{{ form_widget(form.plainPassword.second,{ 'attr': {'class':'form-control' ,'placeholder': 'Repeat your password'} }) }}
{{ form_errors(form.plainPassword.second) }}
</div>
<div class="form-group">
{{ form_widget(form.bio,{ 'attr': {'class': 'form-control','placeholder': 'bio'}}) }}
{{ form_errors(form.bio) }}
</div>
<div class="form-group">
{{ form_errors(form) }}
</div>
{{ form_rest(form) }}
<div class="form-group float-right" style="margin-top: 2%">
<input type="submit" class="submitRegister btn btn-primary" value="{{ 'registration.submit'|trans }}" />
</div>
<div class="form-group float-left">
<a class="loginInRegister nav-link" data-toggle="modal" data-target="#modalLogin">
<input type="submit" class="btn btn-primary" value="Login" />
</a>
</div>
{{ form_end(form) }}
</div>
</div>
<script src="{{ asset('js/main.js') }}"></script>
контроллер:
public function new(Request $request){
$user = new Doctor();
$user->setEnabled(true);
$event = new GetResponseUserEvent($user, $request);
$this->eventDispatcher->dispatch(FOSUserEvents::REGISTRATION_INITIALIZE, $event);
if (null !== $event->getResponse()) {
return $event->getResponse();
}
$form= $this->createForm(DoctorType::class, $user);
$form->setData($user);
$form->handleRequest($request);
if ($form->isSubmitted()) {
if ($form->isValid()) {
$event = new FormEvent($form, $request);
$this->eventDispatcher->dispatch(FOSUserEvents::REGISTRATION_SUCCESS, $event);
//dump($user->getPicture());die;
$url = $this->generateUrl('fos_user_registration_confirmed');
$response = new RedirectResponse($url);
$this->eventDispatcher->dispatch(FOSUserEvents::REGISTRATION_COMPLETED, new FilterUserResponseEvent($user, $request, $response));
return $response;
}
$event = new FormEvent($form, $request);
$this->eventDispatcher->dispatch(FOSUserEvents::REGISTRATION_FAILURE, $event);
if (null !== $response = $event->getResponse()) {
return $response;
}
}
return [
'form' => $form->createView()
];
}
formType:
<?php
namespace App\Form\Type;
use App\Entity\Doctor;
use App\Entity\User;
use PhpParser\Comment\Doc;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
class DoctorType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->remove('username')
->add('firstName')
->add('lastName')
->add('shortBio')
->add('bio',TextareaType::class)
->add('streetAddress')
->add('postalCode')
->add('locality')
->add('region')
->add('picture',FileType::class)
->add('country')
->add('speciality')
;
}
/**
* @return FOS\UserBundle\Form\Type\RegistrationFormType
*/
public function getParent()
{
return 'FOS\UserBundle\Form\Type\RegistrationFormType';
}
/**
* @return string
*/
public function getBlockPrefix()
{
return 'app_doctor_registration';
}
/**
* @return string
*/
public function getName()
{
return $this->getBlockPrefix();
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Doctor::class,
]);
}
}
код объекта - это код документа vichUploadBundle, и у меня возникла ошибка в flush .. объектсбросить в базу данных, но изображение не перемещается в каталог или сохранить изображение в базе данных