setItems() public method

Sets items from which to choose.
public setItems ( array $items, $useKeys = TRUE ) : self
$items array
return self
Ejemplo n.º 1
0
 /**
  * Sets options and option groups from which to choose.
  * @return self
  */
 public function setItems(array $items, $useKeys = TRUE)
 {
     if (!$useKeys) {
         foreach ($items as $key => $value) {
             unset($items[$key]);
             if (is_array($value)) {
                 foreach ($value as $val) {
                     $items[$key][(string) $val] = $val;
                 }
             } else {
                 $items[(string) $value] = $value;
             }
         }
     }
     $this->options = $items;
     return parent::setItems(Nette\Utils\Arrays::flatten($items, TRUE));
 }
Ejemplo n.º 2
0
 /**
  * Sets options and option groups from which to choose.
  *
  * @return self
  */
 public function setItems(array $items, $useKeys = TRUE)
 {
     if (!$useKeys) {
         $res = array();
         foreach ($items as $key => $value) {
             unset($items[$key]);
             if (is_array($value)) {
                 foreach ($value as $val) {
                     $res[$key][(string) $val] = $val;
                 }
             } else {
                 $res[(string) $value] = $value;
             }
         }
         $items = $res;
     }
     $this->options = $items;
     return ChoiceControl::setItems(Arrays::flatten($items, TRUE));
 }