Symfony 小部件在渲染时以编程方式清除标签
Symfony widget clear label programmatically on render
我尝试在执行一些检查后以编程方式设置小部件的标签值,但我的以下尝试无效。谁能看到我做错了什么?请注意,标签已经有一个值,我只想清除它。那是在 symfony 1.4.
class customFormSome extends sfWidgetFormTextarea {
/**
* Constructor.
*
* @see sfWidgetFormTextarea
* */
protected function configure($options = array(), $attributes = array()) {
$this->addOption('element_id');
}
/**
* @param string $name The element name
* @param string $value The value displayed in this widget
* @param array $attributes An array of HTML attributes to be merged with the default HTML attributes
* @param array $errors An array of errors for the field
*
* @see sfWidget
* */
public function render($name, $value = null, $attributes = array(), $errors = array()) {
/*** SOME PROCESSING HERE******/
$this->setAttribute('label', ''); //---->DOESNT WORK
$this->setAttribute('label', FALSE); //---->DOESNT WORK
$this->setAttribute('label', NULL); //---->DOESNT WORK
$fields = $this->parent->setLabel($this->getOption('element_id'), '');//---->DOESNT WORK
}
在render方法中调用setAttiribute()
来不及了,它从$attributes
参数中获取属性,所以你只需要覆盖它:
public function render($name, $value = null, $attributes = array(), $errors = array()) {
/*** SOME PROCESSING HERE******/
$attributes['label'] = $this->getOption('element_id');
return parent::render($name, $value, $attributes, $errors);
}
我尝试在执行一些检查后以编程方式设置小部件的标签值,但我的以下尝试无效。谁能看到我做错了什么?请注意,标签已经有一个值,我只想清除它。那是在 symfony 1.4.
class customFormSome extends sfWidgetFormTextarea {
/**
* Constructor.
*
* @see sfWidgetFormTextarea
* */
protected function configure($options = array(), $attributes = array()) {
$this->addOption('element_id');
}
/**
* @param string $name The element name
* @param string $value The value displayed in this widget
* @param array $attributes An array of HTML attributes to be merged with the default HTML attributes
* @param array $errors An array of errors for the field
*
* @see sfWidget
* */
public function render($name, $value = null, $attributes = array(), $errors = array()) {
/*** SOME PROCESSING HERE******/
$this->setAttribute('label', ''); //---->DOESNT WORK
$this->setAttribute('label', FALSE); //---->DOESNT WORK
$this->setAttribute('label', NULL); //---->DOESNT WORK
$fields = $this->parent->setLabel($this->getOption('element_id'), '');//---->DOESNT WORK
}
在render方法中调用setAttiribute()
来不及了,它从$attributes
参数中获取属性,所以你只需要覆盖它:
public function render($name, $value = null, $attributes = array(), $errors = array()) {
/*** SOME PROCESSING HERE******/
$attributes['label'] = $this->getOption('element_id');
return parent::render($name, $value, $attributes, $errors);
}