我只是碰到了這個建築對我的MVC框架,在剛剛敲定整個文檔之前,我打電話的PreRender在從ServerTag(這反過來從一個DOMElement繼承)繼承一切TextBox控件。有沒有更好的方式來更改PHP中的DOMElement-> tagName屬性?
我發現改變一個DOMElement派生對象的tagName的唯一方法是用一個新的替換爲所有屬性同步到舊的屬性。
這是怎麼看起來代碼:
protected function PreRenderTextarea(WebPage $sender)
{
$textarea = $sender->createElement('textarea');
foreach($this->attributes as $attribute)
{
if ($attribute->name == 'value')
{
$textarea->nodeValue = $attribute->value;
}
else
{
$textarea->setAttribute($attribute->name, $attribute->value);
}
}
$this->parentNode->replaceChild($textarea, $this);
}
public function OnPreRender(WebPage $sender)
{
parent::OnPreRender();
$this->setAttribute('value', $this->Value);
switch($this->Mode)
{
case 'normal' :
$this->setAttribute('type', 'text');
break;
case 'password' :
$this->setAttribute('type', 'password');
break;
case 'multiline' :
$this->PreRenderTextarea($sender);
return;
break;
}
}
那真的只有這樣,才能做到這一點?這種方式具有將控制背後的所有邏輯置零的相當不希望的副作用。
這幾乎是我想通了,即使我不認爲它應該工作方式 – Kris 2008-11-04 22:47:02