Friday, 15 February 2013

php - how to generate entities and schemas for enum in symfony -



php - how to generate entities and schemas for enum in symfony -

i trying generate entities contact information. have first create entity next syntax used have created 1 enum field.

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".

the above command generate entity class when trying generate "entities" class show error command is.

php app/console doctrine:generate:entities banner/testbundle/entity/contact

it show next error.

[doctrine\common\annotations\annotationexception] [semantical error] couldn't find constant male, property banner\testbundle\ entity\contact::$gender. doctrine:generate:entities [--path="..."] [--no-backup] name

i want generate database next fields:

contact.table name-string(255) lastname-string(255) phone:integer(10) gender:enum("male","female") message:text

please help new in symfony

here contact entity file

<?php namespace banner\testbundle\entity; utilize doctrine\orm\mapping 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; /** * id * * @return integer */ public function getid() { homecoming $this->id; } /** * set name * * @param string $name * @return contact */ public function setname($name) { $this->name = $name; homecoming $this; } /** * name * * @return string */ public function getname() { homecoming $this->name; } /** * set lastname * * @param string $lastname * @return contact */ public function setlastname($lastname) { $this->lastname = $lastname; homecoming $this; } /** * lastname * * @return string */ public function getlastname() { homecoming $this->lastname; } /** * set gender * * @param \enum $gender * @return contact */ public function setgender(\enum $gender) { $this->gender = $gender; homecoming $this; } /** * gender * * @return \enum */ public function getgender() { homecoming $this->gender; } /** * set phone * * @param integer $phone * @return contact */ public function setphone($phone) { $this->phone = $phone; homecoming $this; } /** * phone * * @return integer */ public function getphone() { homecoming $this->phone; } /** * set message * * @param string $message * @return contact */ public function setmessage($message) { $this->message = $message; homecoming $this; } /** * message * * @return string */ public function getmessage() { homecoming $this->message; } }

your annotation not in right format. seek :

@orm\column(name="gender", type="string", columndefinition="enum('male', 'femelle')")

and not forget add together

mapping_types: enum: string

below

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

in app/config/config.yml file.

more info enum in doctrine here.

php symfony2 symfony-2.1

No comments:

Post a Comment