财产" date_evenement"也不是其中一种方法" getDateEvenement()"

时间:2016-08-19 09:21:13

标签: php forms symfony

当我尝试创建一个from without form builder class

时,我收到此错误
  

错误:属性" date_evenement"也没有其中一种方法" getDateEvenement()"," dateEvenement()"," isDateEvenement()"," hasDateEvenement()&# 34;," __ get()"在课堂上存在并具有公共访问权限" Upm \ GeneralBundle \ Entity \ Evenement"。

我确信我的Evenement Entity课程中的所有内容都是正确的,但我无法找到错误。

Evenement Entity Class

<?php

namespace Upm\GeneralBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints\DateTime;

/**
  @ORM\Entity(repositoryClass="Upm\GeneralBundle\Repository   \EvenementRepository")
 */
class Evenement
{
/**
 * @var int
 *
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
private $id;

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

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

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

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

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

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

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

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

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


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


/**
 * Set date_saisie
 *
 * @param string $date_saisie
 *
 * @return Evenement
 */
public function setDate_saisie($date_saisie)
{

    $this->date_saisie=$date_saisie;

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

public  function  __construct()
{
   $this->date_saisie =date('d/m/Y G:i:s');
}

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

/**
 * Set date_evenement
 *
 * @param string $date_evenement
 *
 * @return Evenement
 */
public function setDate_evenement($date_evenement)
{

    $this->date_evenement = $date_evenement;

    return $this;
}

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

/**
 * Set heure
 *
 * @param string $heure
 *
 * @return Evenement
 */
public function setHeure($heure)
{
    $this->heure = $heure;

    return $this;
}

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

/**
 * Set fichier
 *
 * @param string $fichier
 *
 * @return Evenement
 */
public function setFichier($fichier)
{
    $this->fichier = $fichier;

    return $this;
}

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

/**
 * Set objet
 *
 * @param string $objet
 *
 * @return Evenement
 */
public function setObjet($objet)
{
    $this->objet = $objet;

    return $this;
}

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

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

    return $this;
}

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

/**
 * Set aime
 *
 * @param integer $aime
 *
 * @return Evenement
 */
public function setAime($aime)
{
    $this->aime = $aime;

    return $this;
}

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

/**
 * Set nonAime
 *
 * @param integer $nonAime
 *
 * @return Evenement
 */
public function setNonAime($nonAime)
{
    $this->nonAime = $nonAime;

    return $this;
}

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

/**
 * Set responsable_evenement
 *
 * @param string $responsable_evenement
 *
 * @return Evenement
 */
public function setResponsable_evenement($responsable_evenement)
{
    $this->responsable_evenement = $responsable_evenement;

    return $this;
}

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

/**
 * Set id_user
 *
 * @param integer $id_user
 *
 * @return Evenement
 */
public function setId_user($id_user)
{
    $this->id_user =$id_user ;

    return $this;
}

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



}

我的表单函数ajouterEvenementAction(Request $ request)是这样的:

$evn = new Evenement();
    $form = $this->createFormBuilder($evn)
->add('date_evenement',TextType::class,array('attr'=>array('class'=>'form-control pull-right','style'=>"width: 100%;",'palceholder'=>'JJ/MM/AAAA')))
->add('heure',TextType::class,array('attr'=>array('class'=>'form-control pull-right','palceholder'=>"hh:mm")))->add('fichier',FileType::class,array('attr'=>array('style'=>'display: none;','class'=>'file')))
->add('objet',TextType::class,array('attr'=>array('class'=>'form-control')))
->add('description',TextareaType::class,array('attr'=>array('class'=>'form-control')))
->add('Responsable_evenement',TextType::class,array('attr'=>array('class'=>'form-control')))
->add('Ajouter',SubmitType::class,array('label'=>"Ajouter l'Evenement",'attr'=>array('class'=>'form-control  btn btn-success')))->getForm();

$form->handleRequest($request);

    if($form->isSubmitted())
    {
        $dateEvent = $form->get("date_evenement");
        $heuerEvent = $form['heure']->getData();
        $nomFichier = date('Ymd').''.date('gisa').'.'.$form['fichier']->getData()->guessExtension();
        $imageEvent =$nomFichier;
        $objetEvent = $form['objet']->getData();
        $descEvent = $form['description']->getData();
        $Responsable_evenement = $form['Responsable_evenement']->getData();

        $evn->setDate_evenement($dateEvent)
            ->setHeure($heuerEvent)
            ->setFichier($imageEvent)
            ->setObjet($objetEvent)
            ->setDescription($descEvent)
            ->setId_user($this->get('security.token_storage')->getToken()->getUser()->getId())
            ->setResponsable_evenement($Responsable_evenement);

        $file = $form->get('fichier')->getData();
        $name =$nomFichier;
        $dir = __DIR__.'/../../../../src/Upm/GeneralBundle/Resources/public/Uploads';

        $file->move($dir, $name) ;

        $em = $this->getDoctrine()->getManager();
        $em->persist($evn);
        $em->flush();
        return $this->redirectToRoute('home_page_admin');}

感谢帮助人员。

2 个答案:

答案 0 :(得分:0)

您将自己的名字命名为

public function getDate_evenement()

虽然Symfony的表单组件希望您将它们命名为:

public function getDateEvenement()

无论如何这是一种标准的方法。

你应该重构你的实体,以经典的方式命名getter。

顺便说一句,你的惯例非常奇怪。

答案 1 :(得分:0)

Symfony2表单组件需要使用方法:getDateEvenement来获取$date_evenement属性的默认值。相反,你有getDate_evenement形式知道nothig。