FOSUserBundle - 嵌入formtype

时间:2017-06-15 13:47:56

标签: forms symfony fosuserbundle

请帮帮我!我想在实体的另一个表单构建器中嵌入FOSUserBundle表单的形式。当我这样做时,用户实体中没有验证测试。我是symfony的新手。 例如:

->add('user', RegistrationType::class)

class FolderType extends AbstractType
{
    /**
     * {@inheritdoc}
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
        ->add('user',                       RegistrationType::class)
        ->add('firstname',                  TextType::class)
        ->add('lastname',                   TextType::class)
        ->add('dateBirth',                  BirthdayType::class)
        ->add('nationality',                CountryType::class,
            array(
            'preferred_choices' => array(
                'France', 'FR')
            ))
        ->add('phone',                      NumberType::class)
        ->add('save',                       SubmitType::class);
    }

在控制器中添加功能:

public function addAction(Request $request, School $schoolId)
    {
        $em     = $this->getDoctrine()->getManager();
        $school = $em->getRepository('SchoolBundle:School')->findOneById($schoolId);
        $candidat = new candidat();
            //School Parameter
            $candidat->setSchool($schoolId);

        $form = $this->createForm('CandidacyBundle\Form\Onepage\FolderType', $candidat, array('schoolId' => $schoolId));

        if($request->isMethod('POST') && $form->handleRequest($request)->isValid())
        {
            //exit(\Doctrine\Common\Util\Debug::dump($candidat));
            $em->persist($candidat);
            $em->flush();
            $this->get('session')->getFlashBag()->add('notice','Yours new candidacy is added !');
            return $this->redirectToRoute('candidacy_home');
        }
        return $this->render('CandidacyBundle:Folder_B:folder.html.twig', array(
            'school' => $school,
            'new_folder' => $form->createView()
        ));
    } 

注册类型

namespace UserBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;

class RegistrationType extends AbstractType{

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        parent::buildForm($builder, $options);
        $builder;
    }
    public function getParent()
    {
        return 'FOS\UserBundle\Form\Type\RegistrationFormType';
    }

    public function getBlockPrefix()
    {
        return 'app_user_registration';
    }

}

CANDIDAT ENTITY     

namespace CandidacyBundle\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Symfony\Component\Validator\Constraints as Assert;

use Doctrine\ORM\Mapping as ORM;
use Gedmo\mapping\Annotation as Gedmo;

use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
 * Candidat
 *
 * @ORM\Table()
 * @ORM\Entity
 */
class Candidat
{
//x - x - x - x - x - x - x - x - x - x - x - x - x - x - OBJ

    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @ORM\OneToOne(targetEntity="UserBundle\Entity\User", cascade={"persist"})
     * @ORM\JoinColumn(nullable=false)
     * @Assert\Valid
     */
    private $user;

    /**
     * @ORM\ManyToOne(targetEntity="SchoolBundle\Entity\School")
     * @ORM\JoinColumn(name="id_school", referencedColumnName="id", nullable=true)
     */
    private $school;

    /**
     * @var boolean
     *
     * @ORM\Column(name="state", type="boolean")
     */
    private $state = true;

    /**
     * @var boolean
     *
     * @ORM\Column(name="state_blacklist", type="boolean")
     */
    private $stateBlacklist = false;

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="date_entry", type="datetime")
     */
    private $dateEntry;

    /**
     * @var string
     * @Assert\NotBlank()
     * @Assert\Length(min=3)
     * @ORM\Column(name="name", type="string", length=255, nullable=true)
     */
    private $firstname;

    /**
     * @var string
     * @Assert\NotBlank(message="Vous devez indiquer votre nom")
     * @Assert\Length(min=3)
     * @Assert\Regex(
     *     pattern="/\d/",
     *     match=false,
     *     message="Uniquement des lettres"
     * )
     * @ORM\Column(name="lastname", type="string", length=255, nullable=true)
     */
    private $lastname;

    /**
     * @var \date
     * @ORM\Column(name="date_birth", type="date", nullable=true)
     */
    private $dateBirth;

    /**
     * @var string
     *
     * @ORM\Column(name="nationality", type="string", length=255, nullable=true)
     */
    private $nationality;

    /**
     * @var integer
     *
     * @ORM\Column(name="phone", type="integer", nullable=true)
     */
    private $phone;

    /**
     * @var string
     *
     * @ORM\Column(name="adress_street", type="string", length=255, nullable=true)
     */
    private $adress_street;

    /**
     * @var string
     *
     * @ORM\Column(name="adress_city", type="string", length=255, nullable=true)
     */
    private $adress_city;

    /**
     * @var string
     *
     * @ORM\Column(name="adress_region", type="string", length=255, nullable=true)
     */
    private $adress_region;

    /**
     * @var string
     *
     * @ORM\Column(name="adress_country", type="string", length=255, nullable=true)
     */
    private $adress_country;

    /**
     * @var integer
     *
     * @ORM\Column(name="adress_zip", type="smallint", nullable=true)
     */
    private $adress_zip;

    /**
     * @ORM\ManyToOne(targetEntity="SchoolBundle\Entity\Level", cascade={"persist"})
     * @ORM\JoinColumn(name="study_current_level", referencedColumnName="id", nullable=true)
     */
    private $studyCurrentLevel;

    /**
     * @var string
     *
     * @ORM\Column(name="study_current_graduate_name", type="string", length=50)
     */
    private $studyCurrentGraduateName;

    /**
     * @ORM\ManyToOne(targetEntity="SchoolBundle\Entity\Graduate", cascade={"persist"})
     * @ORM\JoinColumn(name="study_current_graduate", referencedColumnName="id", nullable=true )
     */
    private $studyCurrentGraduate;

    /**
     * @ORM\ManyToOne(targetEntity="SchoolBundle\Entity\Graduate")
     * @ORM\JoinColumn(name="study_widh_graduate", referencedColumnName="id", nullable=true )
     */
    private $studyWishGraduate;

    /**
     * @ORM\ManyToOne(targetEntity="SchoolBundle\Entity\Sector")
     * @ORM\JoinColumn(nullable=true)
     */
    private $studyWishSector;

    /**
     * @ORM\ManyToMany(targetEntity="SchoolBundle\Entity\Speciality")
     * @ORM\JoinTable(name="candidat_Speciality")
     */
    private $studyWishSpecialities;    

    /**
     * @ORM\ManyToOne(targetEntity="SchoolBundle\Entity\Section")
     * @ORM\JoinColumn(nullable=true)
     */
    private $studyWishSection;

    /**
     * @ORM\ManyToMany(targetEntity="SchoolBundle\Entity\Diploma", cascade={"persist"})
     * @ORM\JoinTable(name="candidat_diploma")
     */
    private $studyWishDiplomas;

    /**
     * @ORM\ManyToOne(targetEntity="SchoolBundle\Entity\Rhythm", cascade={"persist"})
     * @ORM\JoinColumn(name="study_wish_rhythm", referencedColumnName="id", nullable=true)
     */
    private $studyWishRhythm;

    /**
     * @var boolean
     *
     * @ORM\Column(name="study_wish_place_study", type="boolean", nullable=true)
     */
    private $studyWishPlaceStudy;


    /**
     * @ORM\OneToOne(targetEntity="CandidacyBundle\Entity\Attachment", cascade={"all"})
     * @ORM\JoinColumn(name="file_picture", nullable=true)
     */
    private $picture;

    /**
     * @ORM\OneToOne(targetEntity="CandidacyBundle\Entity\Attachment", cascade={"all"})
     * @ORM\JoinColumn(name="file_cv", nullable=true)
     */
    private $cv;

    /**
     * @ORM\ManyToMany(targetEntity="CandidacyBundle\Entity\Attachment",cascade={"persist"})
     * @ORM\JoinTable(name="candidat_attachment")
     */
    private $attachments;


//x - x - x - x - x - x - x - x - x - x - x - x - x - x - CONSTRUCT 

    public function __construct()
    {
        $this->dateEntry        = new \DateTime();
        $this->attachments      = new ArrayCollection();
    }
//x - x - x - x - x - x - x - x - x - x - x - x - x - x - GET/SET

    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set state
     *
     * @param boolean $state
     *
     * @return Candidat
     */
    public function setState($state)
    {
        $this->state = $state;

        return $this;
    }

    /**
     * Get state
     *
     * @return boolean
     */
    public function getState()
    {
        return $this->state;
    }

    /**
     * Set stateBlacklist
     *
     * @param boolean $stateBlacklist
     *
     * @return Candidat
     */
    public function setStateBlacklist($stateBlacklist)
    {
        $this->stateBlacklist = $stateBlacklist;

        return $this;
    }

    /**
     * Get stateBlacklist
     *
     * @return boolean
     */
    public function getStateBlacklist()
    {
        return $this->stateBlacklist;
    }

    /**
     * Set dateEntry
     *
     * @param \DateTime $dateEntry
     *
     * @return Candidat
     */
    public function setDateEntry($dateEntry)
    {
        $this->dateEntry = $dateEntry;

        return $this;
    }

    /**
     * Get dateEntry
     *
     * @return \DateTime
     */
    public function getDateEntry()
    {
        return $this->dateEntry;
    }

    /**
     * Set firstname
     *
     * @param string $firstname
     *
     * @return Candidat
     */
    public function setFirstname($firstname)
    {
        $this->firstname = $firstname;

        return $this;
    }

    /**
     * Get firstname
     *
     * @return string
     */
    public function getFirstname()
    {
        return $this->firstname;
    }

    /**
     * Set lastname
     *
     * @param string $lastname
     *
     * @return Candidat
     */
    public function setLastname($lastname)
    {
        $this->lastname = $lastname;

        return $this;
    }

    /**
     * Get lastname
     *
     * @return string
     */
    public function getLastname()
    {
        return $this->lastname;
    }

    /**
     * Set dateBirth
     *
     * @param \DateTime $dateBirth
     *
     * @return Candidat
     */
    public function setDateBirth($dateBirth)
    {
        $this->dateBirth = $dateBirth;

        return $this;
    }

    /**
     * Get dateBirth
     *
     * @return \DateTime
     */
    public function getDateBirth()
    {
        return $this->dateBirth;
    }

    /**
     * Set email
     *
     * @param string $email
     *
     * @return Candidat
     */
    public function setEmail($email)
    {
        $this->email = $email;

        return $this;
    }

    /**
     * Get email
     *
     * @return string
     */
    public function getEmail()
    {
        return $this->email;
    }

    /**
     * Set nationality
     *
     * @param string $nationality
     *
     * @return Candidat
     */
    public function setNationality($nationality)
    {
        $this->nationality = $nationality;

        return $this;
    }

    /**
     * Get nationality
     *
     * @return string
     */
    public function getNationality()
    {
        return $this->nationality;
    }

    /**
     * Set phone
     *
     * @param integer $phone
     *
     * @return Candidat
     */
    public function setPhone($phone)
    {
        $this->phone = $phone;

        return $this;
    }

    /**
     * Get phone
     *
     * @return integer
     */
    public function getPhone()
    {
        return $this->phone;
    }

    /**
     * Set adressStreet
     *
     * @param string $adressStreet
     *
     * @return Candidat
     */
    public function setAdressStreet($adressStreet)
    {
        $this->adress_street = $adressStreet;

        return $this;
    }

    /**
     * Get adressStreet
     *
     * @return string
     */
    public function getAdressStreet()
    {
        return $this->adress_street;
    }

    /**
     * Set adressCity
     *
     * @param string $adressCity
     *
     * @return Candidat
     */
    public function setAdressCity($adressCity)
    {
        $this->adress_city = $adressCity;

        return $this;
    }

    /**
     * Get adressCity
     *
     * @return string
     */
    public function getAdressCity()
    {
        return $this->adress_city;
    }

    /**
     * Set adressRegion
     *
     * @param string $adressRegion
     *
     * @return Candidat
     */
    public function setAdressRegion($adressRegion)
    {
        $this->adress_region = $adressRegion;

        return $this;
    }

    /**
     * Get adressRegion
     *
     * @return string
     */
    public function getAdressRegion()
    {
        return $this->adress_region;
    }

    /**
     * Set adressCountry
     *
     * @param string $adressCountry
     *
     * @return Candidat
     */
    public function setAdressCountry($adressCountry)
    {
        $this->adress_country = $adressCountry;

        return $this;
    }

    /**
     * Get adressCountry
     *
     * @return string
     */
    public function getAdressCountry()
    {
        return $this->adress_country;
    }

    /**
     * Set adressZip
     *
     * @param integer $adressZip
     *
     * @return Candidat
     */
    public function setAdressZip($adressZip)
    {
        $this->adress_zip = $adressZip;

        return $this;
    }

    /**
     * Get adressZip
     *
     * @return integer
     */
    public function getAdressZip()
    {
        return $this->adress_zip;
    }

    /**
     * Set studyCurrentLevel
     *
     * @param string $studyCurrentLevel
     *
     * @return Candidat
     */
    public function setStudyCurrentLevel($studyCurrentLevel)
    {
        $this->studyCurrentLevel = $studyCurrentLevel;

        return $this;
    }

    /**
     * Get studyCurrentLevel
     *
     * @return string
     */
    public function getStudyCurrentLevel()
    {
        return $this->studyCurrentLevel;
    }

    /**
     * Set studyCurrentGraduateName
     *
     * @param string $studyCurrentGraduateName
     *
     * @return Candidat
     */
    public function setStudyCurrentGraduateName($studyCurrentGraduateName)
    {
        $this->studyCurrentGraduateName = $studyCurrentGraduateName;

        return $this;
    }

    /**
     * Get studyCurrentGraduateName
     *
     * @return string
     */
    public function getStudyCurrentGraduateName()
    {
        return $this->studyCurrentGraduateName;
    }

    /**
     * Set studyCurrentGraduate
     *
     * @param string $studyCurrentGraduate
     *
     * @return Candidat
     */
    public function setStudyCurrentGraduate($studyCurrentGraduate)
    {
        $this->studyCurrentGraduate = $studyCurrentGraduate;

        return $this;
    }

    /**
     * Get studyCurrentGraduate
     *
     * @return string
     */
    public function getStudyCurrentGraduate()
    {
        return $this->studyCurrentGraduate;
    }

    /**
     * Set studyWishGraduate
     *
     * @param string $studyWishGraduate
     *
     * @return Candidat
     */
    public function setStudyWishGraduate($studyWishGraduate)
    {
        $this->studyWishGraduate = $studyWishGraduate;

        return $this;
    }

    /**
     * Get studyWishGraduate
     *
     * @return string
     */
    public function getStudyWishGraduate()
    {
        return $this->studyWishGraduate;
    }

    /**
     * Set studyWishSector
     *
     * @param string $studyWishSector
     *
     * @return Candidat
     */
    public function setStudyWishSector($studyWishSector)
    {
        $this->studyWishSector = $studyWishSector;

        return $this;
    }

    /**
     * Get studyWishSector
     *
     * @return string
     */
    public function getStudyWishSector()
    {
        return $this->studyWishSector;
    }

    /**
     * Set studyWishRhythm
     *
     * @param string $studyWishRhythm
     *
     * @return Candidat
     */
    public function setStudyWishRhythm($studyWishRhythm)
    {
        $this->studyWishRhythm = $studyWishRhythm;

        return $this;
    }

    /**
     * Get studyWishRhythm
     *
     * @return string
     */
    public function getStudyWishRhythm()
    {
        return $this->studyWishRhythm;
    }

    /**
     * Set studyWishPlaceStudy
     *
     * @param string $studyWishPlaceStudy
     *
     * @return Candidat
     */
    public function setStudyWishPlaceStudy($studyWishPlaceStudy)
    {
        $this->studyWishPlaceStudy = $studyWishPlaceStudy;

        return $this;
    }

    /**
     * Get studyWishPlaceStudy
     *
     * @return string
     */
    public function getStudyWishPlaceStudy()
    {
        return $this->studyWishPlaceStudy;
    }

    /**
     * Set user
     *
     * @param guid $user
     *
     * @return \UserBundle\Entity\User $user
     */
    public function setUser($user)
    {
        $this->user = $user;

        return $this;
    }

    /**
     * Get user
     *
     * @return \UserBundle\Entity\User
     */
    public function getUser()
    {
        return $this->user;
    }

    /**
     * Set studyWishSpecialities
     *
     * @param \SchoolBundle\Entity\Speciality $studyWishSpecialities
     *

     * @return Candidat
     */
    public function setStudyWishSpecialities($studyWishSpecialities)
    {
        $this->studyWishSpecialities = $studyWishSpecialities;

        return $this;
    }

    /**
     * Get studyWishSpecialities
     *
     * @return \SchoolBundle\Entity\Speciality
     */
    public function getStudyWishSpecialities()
    {
        return $this->studyWishSpecialities;
    }

    public function setPicture(Attachment $picture = null)
    {
        $this->picture = $picture;
    }
    public function getPicture()
    {
        return $this->picture;
    }

    public function setCv(Attachment $cv = null)
    {
        $this->cv = $cv;
    }
    public function getCv()
    {
        return $this->cv;
    }

    /**
     * Add attachment
     *
     * @param \CandidacyBundle\Entity\Attachment $attachment
     *
     * @return Candidat
     */
    public function addAttachment(\CandidacyBundle\Entity\Attachment $attachment)
    {
        $this->attachments[] = $attachment;

        return $this;
    }

    /**
     * Remove attachment
     *
     * @param \CandidacyBundle\Entity\Attachment $attachment
     */
    public function removeAttachment(\CandidacyBundle\Entity\Attachment $attachment)
    {
        $this->attachments->removeElement($attachment);
    }

    /**
     * Get attachments
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getAttachments()
    {
        return $this->attachments;
    }


    /**
     * Set school
     *
     * @param \SchoolBundle\Entity\School $school
     *
     * @return Candidat
     */
    public function setSchool(\SchoolBundle\Entity\School $school = null)
    {
        $this->school = $school;

        return $this;
    }

    /**
     * Get school
     *
     * @return \SchoolBundle\Entity\School
     */
    public function getSchool()
    {
        return $this->school;
    }

    /**
     * Add studyWishSpeciality
     *
     * @param \SchoolBundle\Entity\Speciality $studyWishSpeciality
     *
     * @return Candidat
     */
    public function addStudyWishSpeciality(\SchoolBundle\Entity\Speciality $studyWishSpeciality)
    {
        $this->studyWishSpecialities[] = $studyWishSpeciality;

        return $this;
    }

    /**
     * Remove studyWishSpeciality
     *
     * @param \SchoolBundle\Entity\Speciality $studyWishSpeciality
     */
    public function removeStudyWishSpeciality(\SchoolBundle\Entity\Speciality $studyWishSpeciality)
    {
        $this->studyWishSpecialities->removeElement($studyWishSpeciality);
    }

    /**
     * Set studyWishSection
     *
     * @param \SchoolBundle\Entity\Section $studyWishSection
     *
     * @return Candidat
     */
    public function setStudyWishSection(\SchoolBundle\Entity\Section $studyWishSection = null)
    {
        $this->studyWishSection = $studyWishSection;

        return $this;
    }

    /**
     * Get studyWishSection
     *
     * @return \SchoolBundle\Entity\Section
     */
    public function getStudyWishSection()
    {
        return $this->studyWishSection;
    }

    /**
     * Add studyWishDiploma
     *
     * @param \SchoolBundle\Entity\Diploma $studyWishDiploma
     *
     * @return Candidat
     */
    public function addStudyWishDiploma(\SchoolBundle\Entity\Diploma $studyWishDiploma)
    {
        $this->studyWishDiploma[] = $studyWishDiploma;

        return $this;
    }

    /**
     * Remove studyWishDiploma
     *
     * @param \SchoolBundle\Entity\Diploma $studyWishDiploma
     */
    public function removeStudyWishDiploma(\SchoolBundle\Entity\Diploma $studyWishDiploma)
    {
        $this->studyWishDiploma->removeElement($studyWishDiploma);
    }

    /**
     * Get studyWishDiploma
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getStudyWishDiploma()
    {
        return $this->studyWishDiploma;
    }

    /**
     * Get studyWishDiplomas
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getStudyWishDiplomas()
    {
        return $this->studyWishDiplomas;
    }
}

0 个答案:

没有答案