2013-04-07 63 views

回答

5

从我的API中看到的,基本上你可以改变它。

我认为是这样的:

当你调用$this->form->getInput('Name')你JFormField物体内(实际上是一个类interits JFormField,这是抽象的内部 - 由JFormFieldText例如继承),调用该方法getInput()

这种方法,getInput(),从我可以从你定义的XML直接看到获取其参数$element(描述表单字段的XML元素的SimpleXMLElement对象)并返回只是一个字符串(实际HTML),所以设置和非现有财产显然不会工作。

但JForm有)称为setFieldAttribute(一个很好的方法,请参见下面的签名:

/** 
* Method to set an attribute value for a field XML element. 
* 
* @param string $name  The name of the form field for which to set the attribute value. 
* @param string $attribute The name of the attribute for which to set a value. 
* @param mixed $value  The value to set for the attribute. 
* @param string $group  The optional dot-separated form group path on which to find the field. 
* 
* @return boolean True on success. 
* 
* @since 11.1 
*/ 
public function setFieldAttribute($name, $attribute, $value, $group = null) 

所以,你的代码可以是这样的:

if(_condition_) 
{ 
    $this->form->setFieldAttribute('Name', 'readonly', 'true', $group = null); 
    echo $this->form->getInput('name'); 
} 

希望这有助于。

+1

很好的答案,这是完美的工作,非常感谢! – user2255093 2013-04-07 22:07:18