如何从请求到表单获取图像实体的URL

时间:2014-07-10 08:42:57

标签: php forms symfony symfony-forms symfony-2.3

我必须从获取其URL的请求中获取图像,然后将此值传递给我的Edit Client表单,因此存在所有代码信息:

控制器

/**
    * @Route("/formulaire" , name="nm")
    * @Template("frm1Form1Bundle:gest:formulaire.html.twig")
    */
   public function formulaireAction(Request $req)
   {


   if($this->verif($req)){
       $cli=new client();
       $form = $this->createFrm($cli);
       $req=$this->getRequest();
       $form->bind($req);
       if($form->isValid()){

        $c=$form->getData();
        $doc=$this->getDoctrine()->getManager();
           $doc->persist($c);
           $doc->flush();
           return $this->render("frm1Form1Bundle:gest:crt.html.twig",array("nom"=>$c->getNom()));
       }


   return array("form"=>$form->createView());
   }else{
       return $this->redirect($this->generateUrl("log"));


     }
   }
   private   function  createFrm(client $client){
    $frmb= $this->createFormBuilder($client);
    $frmb->add('nom',"text")
         ->add("age","integer")
         ->add("image","url")
         ->add("envoyer","submit");
    $form=$frmb->getForm();
       return $form;
   }

实体: --client:

 <?php

namespace frm1\Form1Bundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * client
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="frm1\Form1Bundle\Entity\clientRepository")
 */
class client
{
/**
 * @var integer
 *
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
private $id;

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

/**
 * @var integer
 *
 * @ORM\Column(name="age", type="integer")
 */
private $age;
/**
 * @ORM\OneToOne(targetEntity="frm1\Form1Bundle\Entity\image" , cascade={"persist"})
 *
 */
private $image;

public function getId()
{
    return $this->id;
}

/**
 * Set nom
 *
 * @param string $nom
 * @return client
 */
public function setNom($nom)
{
    $this->nom = $nom;

    return $this;
}

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

/**
 * Set age
 *
 * @param integer $age
 * @return client
 */
public function setAge($age)
{
    $this->age = $age;

    return $this;
}

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




/**
 * Set image
 *
 * @param \frm1\Form1Bundle\Entity\image $image
 * @return client
 */
public function setImage($image = null)
{

    $this->image = new image();
    $this->image->setUrl($image);
    return $this;
}

/**
 * Get image
 *
 * @return \frm1\Form1Bundle\Entity\image
 */
public function getImage()
{


    return $this->image;
}
}

- 图像:

 <?php

namespace frm1\Form1Bundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * image
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="frm1\Form1Bundle\Entity\imageRepository")
 */
class image
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

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


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

    /**
     * Set url
     *
     * @param string $url
     * @return image
     */
    public function setUrl($url)
    {
        $this->url = $url;

        return $this;
    }

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

那么我能为此任务做些什么,提前谢谢你:)

0 个答案:

没有答案