表格未提交。没有显示错误

时间:2018-03-11 19:10:48

标签: symfony

我遇到了表格问题

我提交表单时未提交表单。没有显示错误。

我填写了该字段,但当我在表单部分检查分析器时,它表示表单未提交:

Option  Passed Value    Resolved Value
action  

"/Symfony/web/app_dev.php/auth/fr/user/add"

    same as passed value
data    

Annonce {#4948 ▼
  -id: null
  -prix: null
  -datepublication: DateTime @1520793937 {#5015 ▶}
  -auteurId: 1
  -titre: null
  -auteurName: null
  -contenu: null
  -ville: null
  -categorie: null
  -nbplace: null
  -commentaires: ArrayCollection {#5014 …}
}

    same as passed value

这里控制器方法绑定到:

amespace CP\CocolocBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use CP\CocolocBundle\Entity\commentaire;
use CP\CocolocBundle\Entity\Annonce;
use CP\CocolocBundle\Form\AnnonceType;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use CP\UserBundle\Entity\User;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;


/**
*@Route ("/auth/{_locale}")

* /

class AnnonceController extends Controller{


    /**
    * @Route("/user/add", name="addAnnonce")
    * @return Symfony\Component\HttpFoundation\Response
    * @throws \LogicException
    */

    public function newAction (Request $request){

        $annonce = new Annonce();

        $userId= $this->getUser()->getId();

         $form = $this->createForm(AnnonceType::class, $annonce,[
            'action'=>$this->generateUrl('addAnnonce')
        ]);

        $annonce->setAuteurId($userId);
        $form->handleRequest($request);
        if (!$form->isSubmitted() || ! $form->isValid()){

            return $this->render('@CPCocoloc/Annonce/new.html.twig',[
                'form'=> $form->createView(),
            ]);
        }

        $em = $this->getDoctrine()->getManager();
        $em->persist($annonce);
        $em->flush();

        $this->addFlash('notice', 'Annonce postée');

        return $this->redirectToRoute('index');

    }
}

这是实体:

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * Annonce
 *
 * @ORM\Table(name="annonce")
 * @ORM\Entity(repositoryClass="CP\CocolocBundle\Repository\AnnonceRepository")
 */
class Annonce
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var float
     *
     * @ORM\Column(name="prix", type="float")
     */
    private $prix;

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

    /**
     * @var int
     *
     * @ORM\Column(name="auteurId", type="integer")
     */
    private $auteurId;

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

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

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

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

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

    /**
     * @var int
     *
     * @ORM\Column(name="Nbplace", type="integer")
     */
    private $nbplace;

    /**
    *@ORM\OneToMany(targetEntity="commentaire", mappedBy="annonce")
    */

    private $commentaires;



    public function __construct(){
        $this->commentaires = new ArrayCollection();
        $this->datepublication = new \Datetime();
    }


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

    /**
     * Set prix
     *
     * @param float $prix
     *
     * @return Annonce
     */
    public function setPrix($prix)
    {
        $this->prix = $prix;

        return $this;
    }

    /**
     * Get prix
     *
     * @return float
     */
    public function getPrix()
    {
        return $this->prix;
    }

    /**
     * Set datepublication
     *
     * @param \DateTime $datepublication
     *
     * @return Annonce
     */
    public function setDatepublication($datepublication)
    {
        $this->datepublication = $datepublication;

        return $this;
    }

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

    /**
     * Set auteurId
     *
     * @param integer $auteurId
     *
     * @return Annonce
     */
    public function setAuteurId($auteurId)
    {
        $this->auteurId = $auteurId;

        return $this;
    }

    /**
     * Get auteurId
     *
     * @return int
     */
    public function getAuteurId()
    {
        return $this->auteurId;
    }

    /**
     * Set auteurName
     *
     * @param string $auteurName
     *
     * @return Annonce
     */
    public function setAuteurName($auteurName)
    {
        $this->auteurName = $auteurName;

        return $this;
    }

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

  /**
     * Set titre
     *
     * @param string $titre
     *
     * @return Annonce
     */
    public function setTitre($titre)
    {
        $this->titre = $titre;

        return $this;
    }

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


    /**
     * Set contenu
     *
     * @param string $contenu
     *
     * @return Annonce
     */
    public function setContenu($contenu)
    {
        $this->contenu = $contenu;

        return $this;
    }

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

    /**
     * Set ville
     *
     * @param string $ville
     *
     * @return Annonce
     */
    public function setVille($ville)
    {
        $this->ville = $ville;

        return $this;
    }

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

    /**
     * Set categorie
     *
     * @param string $categorie
     *
     * @return Annonce
     */
    public function setCategorie($categorie)
    {
        $this->categorie = $categorie;

        return $this;
    }

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

    /**
     * Set nbplace
     *
     * @param integer $nbplace
     *
     * @return Annonce
     */
    public function setNbplace($nbplace)
    {
        $this->nbplace = $nbplace;

        return $this;
    }

    /**
     * Get nbplace
     *
     * @return int
     */
    public function getNbplace()
    {
        return $this->nbplace;
    }


        public function getCommentaires(){
        return $this->commentaires;
    }

    public function addCommentaires(commentaire $commentaire){
        $this->commentaires [] = $commentaire;
    }
}

我使用命令创建了表单。我设法将用户留在数据库中。

0 个答案:

没有答案