Orion PHP  0.11.12
The PHP5.3 framework
select.php
Go to the documentation of this file.
00001 <?php
00002 namespace Orion\Core\Model;
00003 
00004 
00005 class Select extends Field
00006 {
00007         protected $data;
00008     /**
00009      * List model field
00010      * @param string $bind
00011      * @param string $label
00012          * @param array $data The associative data array. (keys are the values' label)
00013      * @param boolean $primary
00014      */
00015     public function __construct($bind='select', $label='List', $data=array(), $required=true)
00016     {
00017         $this->type = 'select';
00018         $this->bind = $bind;
00019         $this->label = $label;
00020                 $this->data = $data;
00021         $this->required = $required;
00022     }
00023 
00024     public function toHtml($XHTML=true)
00025     {
00026         if($XHTML)
00027             $tag = ' /';
00028         else
00029             $tag = '';
00030 
00031                 $tmp = '<div class="form-row"><label for="'.$this->bind.'">'.$this->label.'</label><div class="form-container"><select class="form-element" name="'.$this->bind.'">'."\n";
00032                 foreach($this->data as $key => $val)
00033                         $tmp .= '<option value="'.$val.'"'. ($this->value == $val ? ' selected="selected"' : '') .'>'.$key.'</option>'."\n";
00034                 $tmp .= '</select></div></div>';
00035         
00036         return $tmp;
00037     }
00038 
00039     public function getData()
00040     {
00041         return $this->data;
00042     }
00043 }
00044 
00045 ?>