rex_fragment::setVar PHP Method

setVar() public method

Set the variable $name to the given value.
public setVar ( string $name, mixed $value, boolean $escape = true )
$name string The name of the variable
$value mixed The value for the variable
$escape boolean Flag which indicates if the value should be escaped or not
    public function setVar($name, $value, $escape = true)
    {
        if (is_null($name)) {
            throw new InvalidArgumentException(sprintf('Expecting $name to be not null!'));
        }
        if ($escape) {
            $this->vars[$name] = $this->escape($value);
        } else {
            $this->vars[$name] = $value;
        }
    }

Usage Example

Exemplo n.º 1
0
 public function formatElement()
 {
     $s = '';
     $values = explode('|', trim($this->getValue(), '|'));
     $options = $this->getOptions();
     $name = $this->getAttribute('name');
     $id = $this->getAttribute('id');
     $attr = '';
     foreach ($this->getAttributes() as $attributeName => $attributeValue) {
         if ($attributeName == 'name' || $attributeName == 'id') {
             continue;
         }
         $attr .= ' ' . htmlspecialchars($attributeName) . '="' . htmlspecialchars($attributeValue) . '"';
     }
     $formElements = [];
     foreach ($options as $opt_name => $opt_value) {
         $opt_id = $id;
         if ($opt_value != '') {
             $opt_id .= '-' . rex_string::normalize($opt_value, '-');
         }
         $opt_attr = $attr . ' id="' . htmlspecialchars($opt_id) . '"';
         $checked = in_array($opt_value, $values) ? ' checked="checked"' : '';
         $n = [];
         $n['label'] = '<label class="control-label" for="' . htmlspecialchars($opt_id) . '">' . htmlspecialchars($opt_name) . '</label>';
         $n['field'] = '<input type="checkbox" name="' . htmlspecialchars($name) . '[' . htmlspecialchars($opt_value) . ']" value="' . htmlspecialchars($opt_value) . '"' . $opt_attr . $checked . ' />';
         $formElements[] = $n;
     }
     $fragment = new rex_fragment();
     $fragment->setVar('elements', $formElements, false);
     $fragment->setVar('grouped', true);
     $s = $fragment->parse('core/form/checkbox.php');
     return $s;
 }
All Usage Examples Of rex_fragment::setVar