Question

I want to make a choice dropdown form with three choices: -favored -intended -verified so i could'nt use a boolean for this.

I have no idea how to set my annotations for my status field in the entity. Any help?

  /**
     * @var boolean
     *
     * @ORM\Column(name="status", type="boolean")
     */
    private $status;
Was it helpful?

Solution

I don't know if I have really understood your question but in fact the boolean field type for symfony2/doctrine2 is a tinyint(1) in SQL database. So you can put integer values from -128 to 127.

Generally for my entities I use this "rule" :

<?php

class MyEntity
{
     const STATUS_FAVORED  = 1;
     const STATUS_INTENTED = 2;
     const STATUS_VERIFIED = 3;


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


     public function __construct()
     {
         $this->status = self::STATUS_FAVORED;
     }


     /**
      * For ur form by example
      */
     public static function getStatusForChoiceFormField()
     {
         return array(
            self::STATUS_FAVORED  => 'favored',
            self::STATUS_INTENTED => 'intented',
            self::STATUS_VERIFIED => 'verified'

         );
     }
}

?>

See u !

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top