Joomla! Programmierung/Framework/JHtmlSelect/option

Aus Joomla! Dokumentation
Wechseln zu: Navigation, Suche

Erzeugt ein Objekt, das zur Weiterverarbeitung an eine Listenmethode übergeben werden kann.

Inhaltsverzeichnis

[Bearbeiten] Syntax

option( $value, $text, $value_name, $text_name, $disable )
  • @static
  • @return object mit Listenwerten
  • @since Joomla 1.5
Parameter Datentyp Beschreibung Standardwert
$value string Wert des <option> Feldes.
$text string Text des <option> Feldes.
$value_name string Name des Objektattributes, dass den Wert enthält. value
$text_name string Name des Objektattributes, dass den Text enthält. text
$disable bool Setzt das <option> Feld auf disable="disable" false

[Bearbeiten] Beispiele

[Bearbeiten] Werte in Objekt umwandeln

$wert = array('wert1', 'wert2', 'wert3', 'wert4');
 
$text = array('text1', 'text2', 'text3', 'text4');
 
$option = array();
 
foreach ($wert as $key => $value) {
 
    $option[] = JHtml::_('select.option', $wert[$key], $text[$key]);
 
}
 
print_r($option);

Ausgabe:

Array
(
    [0] => stdClass Object
        (
            [value] => wert1
            [text] => text1
            [disable] => 
        )
 
    [1] => stdClass Object
        (
            [value] => wert2
            [text] => text2
            [disable] => 
        )
 
    [2] => stdClass Object
        (
            [value] => wert3
            [text] => text3
            [disable] => 
        )
 
    [3] => stdClass Object
        (
            [value] => wert4
            [text] => text4
            [disable] => 
        )
 
)

[Bearbeiten] Quellcode

JHtmlSelect::option in Joomla! 2.5.4

Folder blue.png libraries

  • Folder red.png joomla
    • Folder green.png html
      • Folder yellow.png html
        • File php.png select.php
  1. public static function option($value, $text = '', $optKey = 'value', $optText = 'text', $disable = false)
  2. {
  3. $options = array('attr' => null, 'disable' => false, 'option.attr' => null, 'option.disable' => 'disable', 'option.key' => 'value',
  4. 'option.label' => null, 'option.text' => 'text');
  5. if (is_array($optKey))
  6. {
  7. // Merge in caller's options
  8. $options = array_merge($options, $optKey);
  9. }
  10. else
  11. {
  12. // Get options from the parameters
  13. $options['option.key'] = $optKey;
  14. $options['option.text'] = $optText;
  15. $options['disable'] = $disable;
  16. }
  17. $obj = new JObject;
  18. $obj->$options['option.key'] = $value;
  19. $obj->$options['option.text'] = trim($text) ? $text : $value;
  20.  
  21. /*
  22.   * If a label is provided, save it. If no label is provided and there is
  23.   * a label name, initialise to an empty string.
  24.   */
  25. $hasProperty = $options['option.label'] !== null;
  26. if (isset($options['label']))
  27. {
  28. $labelProperty = $hasProperty ? $options['option.label'] : 'label';
  29. $obj->$labelProperty = $options['label'];
  30. }
  31. elseif ($hasProperty)
  32. {
  33. $obj->$options['option.label'] = '';
  34. }
  35.  
  36. // Set attributes only if there is a property and a value
  37. if ($options['attr'] !== null)
  38. {
  39. $obj->$options['option.attr'] = $options['attr'];
  40. }
  41.  
  42. // Set disable only if it has a property and a value
  43. if ($options['disable'] !== null)
  44. {
  45. $obj->$options['option.disable'] = $options['disable'];
  46. }
  47. return $obj;
  48. }

[Bearbeiten] Siehe auch

Meine Werkzeuge
Namensräume
Varianten
Aktionen
Navigation
Sonstiges
Team Navigation
Werkzeuge