Нужна помощь, чтобы восстановить класс, который будет генерировать группу Радио


Я хочу создать радиогруппу с последней опцией радиокнопка с текстом поля ввода этот класс также должен создать радиогруппу без этого поля ввода, если это необходимо. Это класс:

class Radio extends PFBCOptionElement {
    protected $_attributes = array("type" => "radio", "class" => "custom");
    protected $inline;
        protected $_hasOtherTextfield;

  public function __construct($label, $name, $properties, $hasOtherTextfield) {
    $this->_hasOtherTextfield = $hasOtherTextField;
    parent::__construct($label, $name, $properties);
  }

    public function render() { 
        $labelClass = $this->_attributes["type"];
        if(!empty($this->inline))
            $labelClass .= " inline";

        $count = 0;
        foreach($this->options as $value => $text) {
            $value = $this->getOptionValue($value);

            echo '<div class="radio"><label class="form-control', $labelClass . '"> <input id="', $this->_attributes["id"], '-', $count, '"', $this->getAttributes(array("id", "value", "checked")), ' value="', $this->filter($value), '"';
            if(isset($this->_attributes["value"]) && $this->_attributes["value"] == $value)
                echo ' checked="checked"';
            echo '/> ', $text, ' </label></div> ';
            ++$count;
        }   

    if ($this->hasOtherTextField) {
    echo '<div class="radio"><label class="form-control', $labelClass . '"> <input id="', $this->_attributes["id"], '-', $count, '"', $this->getAttributes(array("id", "value", "checked")), ' value="', $this->filter($value), '"';
            if(isset($this->_attributes["value"]) && $this->_attributes["value"] == $value)
                echo ' checked="checked"';
            echo '/> ', $text, ' </label></div>';

      echo '<input type="text" name=""/>';
    }
    }
}

И это класс OptionElement:

abstract class OptionElement extends Element {
    protected $options;

    public function __construct($label, $name, array $options, array $properties = null) {
        $this->options = $options;
        if(!empty($this->options) && array_values($this->options) === $this->options)
            $this->options = array_combine($this->options, $this->options);

        parent::__construct($label, $name, $properties);
    }

    protected function getOptionValue($value) {
        $position = strpos($value, ":pfbc");
        if($position !== false) {
            if($position == 0)
                $value = "";
            else
                $value = substr($value, 0, $position);
        }
        return $value;
    }
}

И здесь я генерирую радиогруппу:

$form->addElement(new ElementRadio("My Selected Radio Buttons", "Radio", array("Option #1", "test"),  true //this will be the last option to generate radio with input)); 

Итак, в этом коде у меня есть ошибка:

Notice: Undefined variable: hasOtherTextField in

И

Notice: Undefined property: PFBCElementRadio::$hasOtherTextField
1 2

1 ответ:

Небольшие ошибки в рендере класса Radio tmethod.

Первая ошибка (имена переменных чувствительны к регистру!):

Использовать

$this->_hasOtherTextfield = $hasOtherTextfield;

Вместо

$this->_hasOtherTextfield = $hasOtherTextField;

Вторая ошибка (неверное имя переменной): Использовать

if ($hasOtherTextField) { ... }

Или

if ($this->_hasOtherTextField) { ... }

Вместо

if ($this->hasOtherTextField) {