添加Form Symfony2

问题描述 投票:0回答:1

我使用symfony2:我有3个实体Piece,Brand和model。添加一件作品时,我必须注明品牌和型号。当我做CRUD时,一切正常,它向我展示了所有的品牌和型号。除了我想要的时候我选择这个品牌,它只向我展示了与这个品牌相关的模特。

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

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

    /**
     * @var string
     *
     * @ORM\Column(name="description", type="text")
     */
    private $description;

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

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

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

    /**
     * @ORM\ManyToOne(targetEntity="Modele", cascade={"persist"})
     * @ORM\JoinColumn(nullable=false)
     */
    private $modele;

    /**
     * @ORM\ManyToOne(targetEntity="Localisation", cascade={"persist"})
     * @ORM\JoinColumn(nullable=false)
     */
    private $localisation;


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

    /**
     * Set refference
     *
     * @param string $refference
     * @return Piece
     */
    public function setRefference($refference)
    {
        $this->refference = $refference;

        return $this;
    }

    function getModele() {
        return $this->modele;
    }

    function setModele($modele) {
        $this->modele = $modele;
    }

    function getLocalisation() {
        return $this->localisation;
    }

    function setLocalisation($localisation) {
        $this->localisation = $localisation;
    }

    function getMar() {
        $m=new Marque();
        return $m->getNom();
    }



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

    /**
     * Set description
     *
     * @param string $description
     * @return Piece
     */
    public function setDescription($description)
    {
        $this->description = $description;

        return $this;
    }

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

    /**
     * Set ref1
     *
     * @param string $ref1
     * @return Piece
     */
    public function setRef1($ref1)
    {
        $this->ref1 = $ref1;

        return $this;
    }

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

    /**
     * Set ref2
     *
     * @param string $ref2
     * @return Piece
     */
    public function setRef2($ref2)
    {
        $this->ref2 = $ref2;

        return $this;
    }

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

    /**
     * Set ref3
     *
     * @param string $ref3
     * @return Piece
     */
    public function setRef3($ref3)
    {
        $this->ref3 = $ref3;

        return $this;
    }

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

PieceType.php

   public function buildForm(FormBuilderInterface $builder, array $options){
        $builder->add('refference')
                ->add('description')
                ->add('localisation')
                ->add('ref1')
                ->add('ref2')
                ->add('ref3')
                ->add('marque')
                ->add('modele');
    }

Example of my add

建议好吗?

php forms symfony
1个回答
0
投票

如果你不想使用AJAX,你可以使用CraueFormFlowBundle创建一个包含不同步骤的FormType,并在symfony中制定一些规则。

© www.soinside.com 2019 - 2024. All rights reserved.