
Mam mały problem: Napisałem klasę odpowiedzialną za kompilowanie szablonów, ale nie udało mi się rozwiązać problemu zapętlania subsekcji:
template.php
<? class Template { var $uncompiled; // szablon nie skompilowany var $compiled; //szablon skompilowany var $sub_uncompiled; // nieskompilowana zawartość subsekcji var $sub_compiled; // skompilowana zawartość subsekcji var $template; function LoadTemplate($template) { die (\"<span style='color: red; font-family: Garamond;'><center>Błąd Krytyczny:<br>nBrak szablonu <b>$template</b>. Skontaktuj się z administratorem serwisu.</center></span>\"); else { $this -> template = $template; } } function Subsection() { { $sub = $this -> subsection[$i]; { $this -> uncompiled = $text; } } return $this -> uncompiled; } function Compile() { { $this -> uncompiled = $text; $this -> compiled = $text; } $this -> compiled = \"n<!-- \". $this -> template .\" -->n\". $this -> compiled .\"n<!-- /\". $this -> template. \" -->n\"; return $this -> compiled; } } ?>
index.php
<? include_once('template.php'); $tpl = new Template; $tpl -> LoadTemplate(\"template/index_body.tpl\"); \"TITLE\" => \"tytuł\", \"AUTHOR\" => \"autor\", \"DATE\" => \"data\", \"NEWS\" => \"news\" ); \"newsrow\" ); $tpl -> Subsection(); \"LINK\" => \"linki\" ); $tpl -> Compile(); ?>
index_body.tpl
<table align="center" width="450" height="10" cellpadding="0" cellspacing="0"> <table align="center" width="440" cellpadding="0" cellspacing="0"> <!-- BEGIN newsrow --> <table align="center" width="420" cellpadding="0" cellspacing="0"> {newsrow.NEWS} </table> <table align="center" width="420" height="20" cellpadding="0" cellspacing="0"> </table> <!-- END newsrow --> {LINK} </table> </table>
Jak widać napisałem funkcję, która znajduje wszystkie dane do zamiany z odpowiednią sekcją(tu akurat {newsrow.COŚ_TAM}), ale nie umiem napisać funkcji, któraby wzięła tekst znajdujący się pomiędzy <!-- BEGIN newsrow --> a <!-- END newsrow --> i zapętliłaby go odpwiednią ilość razy(np. tyle ile jest newsów w bazie danych) dodawając za każdym razem odpowiednią wartość między {}(np. za pierwszym razem w {newsrow.NEWS} wstawiłoby news1, za kolejnym news2, itd.).
Pomoże mi ktoś?
----------
Prosze uzywac [php] do umieszczania kodu php
hwao