2013-02-18 10 views
12

sto provando a generare entità per le mie informazioni di contatto. per questo ho creato prima Entità con la seguente sintassi usata dove ho creato un campo enum.come generare entità e schemi per enum in symfony

php app/console doctrine:generate:entity --entity="BannerTestBundle.contact" --fields="name:string(255) lastname:string(255) phone:integer(10) gender:enum("male","female") message:text". 

Il comando sopra generare la classe entità, ma quando sto cercando di generare "entità" dalla classe mostrerà l'errore il comando è.

php app/console doctrine:generate:entities Banner/TestBundle/Entity/contact 

mostrerà il seguente errore.

[Doctrine\Common\Annotations\AnnotationException] 
[Semantical Error] Couldn't find constant male, property Banner\TestBundle\ 
Entity\contact::$gender. 

doctrine:generate:entities [--path="..."] [--no-backup] name 

voglio generare banca dati con i seguenti campi:

Contact.table 
Name-string(255) 
LastName-string(255) 
Phone:integer(10) 
gender:enum("male","female") 
message:text 

si prega di aiutare in esso come io sono nuovo in symfony

Qui è il file di contatto Entity

<?php 

    namespace Banner\TestBundle\Entity; 

    use Doctrine\ORM\Mapping as ORM; 

    /** 
* contact 
* 
* @ORM\Table() 
* @ORM\Entity(repositoryClass="Banner\TestBundle\Entity\contactRepository") 
*/ 
class contact 
{ 
/** 
* @var integer 
* 
* @ORM\Column(name="id", type="integer") 
* @ORM\Id 
* @ORM\GeneratedValue(strategy="AUTO") 
*/ 
private $id; 

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

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

/** 
* @var enum 
* 
* @ORM\Column(name="gender", type="enum", length=male,female) 
*/ 
private $gender; 

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

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


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

/** 
* Set name 
* 
* @param string $name 
* @return contact 
*/ 
public function setName($name) 
{ 
    $this->name = $name; 

    return $this; 
} 

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

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

    return $this; 
} 

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

/** 
* Set gender 
* 
* @param \enum $gender 
* @return contact 
*/ 
public function setGender(\enum $gender) 
{ 
    $this->gender = $gender; 

    return $this; 
} 

/** 
* Get gender 
* 
* @return \enum 
*/ 
public function getGender() 
{ 
    return $this->gender; 
} 

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

    return $this; 
} 

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

/** 
* Set message 
* 
* @param string $message 
* @return contact 
*/ 
public function setMessage($message) 
{ 
    $this->message = $message; 

    return $this; 
} 

/** 
* Get message 
* 
* @return string 
*/ 
public function getMessage() 
{ 
    return $this->message; 
} 
} 
+0

Mostraci la parte della tua Entità con le annotazioni da $ gender. – Stony

risposta

21

tuo l'annotazione non è nel formato giusto. Prova questo:

@ORM\Column(name="gender", type="string", columnDefinition="enum('male', 'femelle')") 

E non dimenticate di aggiungere

mapping_types: 
    enum: string 

sotto

doctrine: 
    dbal: 
     driver: %database_driver% 
     host:  %database_host% 
     port:  %database_port% 
     dbname: %database_name% 
     user:  %database_user% 
     password: %database_password% 
     charset: UTF8 

nel file app/config/config.yml.

Ulteriori informazioni sull'enum nella dottrina here.

+0

Dopo aver modificato in base al tuo suggerimento, viene visualizzato l'errore seguente. [Doctrine \ ORM \ Mapping \ MappingException] La classe "Banner \ TestBundle \ Entity \ Contact" non è un'entità valida o una super classe mappata. doctrine: generate: entity [--path = "..."] [--no-backup] nome –

+0

Provare a rimuovere la lunghezza dalle annotazioni del telefono. Non è possibile specificare una lunghezza per un numero intero – Pierrickouw

+0

lo stesso errore è in arrivo –

Problemi correlati