所以我写了一个基本类,我已经扩展它来创建 html 元素。基于 Zend - 但不完全是。不,这不是关于 zend 或与 zend 相关的问题
class AisisCore_Form_Elements_Input extends AisisCore_Form_Element {
protected $_html = '';
public function init(){
foreach($this->_options as $options){
$this->_html .= '<input type="text" ';
if(isset($options['id'])){
$this->_html .= 'id="'.$options['id'].'" ';
}
if(isset($options['class'])){
$this->_html .= 'class="'.$options['class'].'" ';
}
if(isset($options['attributes'])){
foreach($options['attributes'] as $attrib){
$this->_html .= $attrib;
}
}
$this->_html .= $this->_disabled;
$this->_html .= ' />';
return $this->_html;
}
}
}
所以这个类扩展了我的元素类,它由一个接受一组选项的构造函数组成,一个基本元素的设置如下:
$array_attrib = array(
'attributes' => array(
'placeholder' => 'Test'
)
);
$element = new AisisCore_Form_Elements_Input($array_attrib);
echo $element;
所以有什么问题?
回显 $element 对象给我一个错误,说它不能将对象转换为字符串,因此当我 var_dump 它时,我得到了这个:
object(AisisCore_Form_Elements_Input)#21 (3) {
["_html":protected]=>
string(22) "<input type="text" />"
["_options":protected]=>
array(1) {
["attributes"]=>
array(1) {
["placeholder"]=>
string(4) "Test"
}
}
["_disabled":protected]=>
NULL
}
有人可以解释发生了什么吗?最后我检查我正在回显一个字符串而不是一个对象。我是如何设法创建一个对象的?
如果您需要查看 AisisCore_Form_Element 类,我将发布它,但所有此类都是您扩展以创建元素的基类。唯一需要的是一系列选项。