09/10/2018, 23:11
hỏi về lập trình template với PHP
có bác nào rành về template chỉ cho em cái này với
nghe nói lập trình template rất hay mà chưa biết bắt đầu ra sao
các bác giúp em với nha
nghe nói lập trình template rất hay mà chưa biết bắt đầu ra sao
các bác giúp em với nha
Bài liên quan
nói biết thì chỉ giúp mình với
nói rõ hơn dược ko dzay, chưa bit nó là cái ji cả
Còn đây là class viết tạm bợ. Xem thử xem sao đã.
<?php
class Template {
var $doc;
function Template($template) {
loadTemplate($template);
}
function loadTemplate($template) {
$doc = new DOMDocument();
$doc->loadHTMLFile($template);
$this->doc = $doc;
}
function getElementsByTagName($tagName) {
return $this->doc->getElementsByTagName($tagName);
}
function getElementByTagName($tagName,$index) {
return $this->getElementsByTagName($tagName)->item(index);
}
function getElementById($id) {
return $this->doc->getElementById($id);
}
function getElementByName($name) {
return $this->doc->getElementByName($name);
}
function appendTextToElement($text,$element) {
$textObj = $doc->createTextNode($text);
$element.appendChild($textObj);
}
function setElementAttribute($attributeName,$attributeValue,$element) {
$element.setAttribute($attributeName,$attributeValue);
}
function getElementAttribute($attributeName,$element) {
return $element.getAttribute($attributeName);
}
}
?>