我希望有人可以帮助我,我是 oop starter,下面的脚本给出了输出<
,但我想要这个<input type="text">
。
现在我创建了一个 Build 类,但它不起作用。我做错了什么,我该如何解决?
有人可以帮助我吗?谢谢!
//set get Element
class Element {
private $_element;
function addElement($element) {
$this->_element = $element;
}
function getElement(){
return $this->_element;
}
}
//add and set Atrr
class attrType extends Element {
//set var
public $_attrType;
function __construct(){
$this->_attrType = array();
}
function addAttr($attrType, $attrValue){
$this->_attrType[$attrType] = $attrValue;
}
function getAttr(){
return $this->_attrType;
}
}
//build input text field
class Build extends attrType {
function Builder() {
$html .= "<";
$html .= ''.$this->getElement();
foreach( $this->getAttr() as $key => $value){
$html .= " $key=";
$html .= "\"$value\">";
}
return $html;
}
}
$element = new Element();
$attr = new attrType();
$build = new Build();
$attr->addElement('input');
$attr->addAttr('type','text');
echo $build->Builder();