![]() |
![]() |
![]()
Post
#1
|
|
Grupa: Zarejestrowani Postów: 1 640 Pomógł: 28 Dołączył: 13.02.2003 Skąd: Międzyrzecz/Poznań Ostrzeżenie: (0%) ![]() ![]() |
Proboje napisac wlasna klase do obslugi szablonow, jakos mi to idzie, (dopiero zaczynam zabawe z klasami) i jest o pewnien problem.
Mam cos takiego:[php:1:4c0c784fef]<?php class Templates { function LoadFile($file_id, $file_name, $file_path) { if(file_exists($file_path.'/'.$file_name)) { $file_open = fopen($file_path.'/'.$file_name, "r"); $file_content = fread($file_open, filesize($file_path.'/'.$file_name)); fclose($file_open); $this -> dane = $file_content; } else { return false; } } function Content($name, $value) { $file_display = str_replace('{'.$name.'}', $value, $this->dane); //W jaki sposob (chyba bedzie potrzeba petla) zrobic zeby //kazda blok byl podmieniany?? $this -> Replace = $file_display; } function Display() { return $this-> Replace; } } $template = new Templates; $template -> LoadFile('start', 'start.tpl', '../templates'); $template -> Content('title', 'Tytul Strony'); $template -> Content('body', 'fksdufdut8'); $template -> Content('itp', '<font color=red>gdsg</font>'); echo $template -> Display(); ?>[/php:1:4c0c784fef] |
|
|
![]() |
![]()
Post
#2
|
|
Developer Grupa: Moderatorzy Postów: 2 844 Pomógł: 20 Dołączył: 25.11.2003 Skąd: Olkusz ![]() |
[php:1:0cee5d68c0]<?php
function Content($name, $value) { $file_display = str_replace('{'.$name.'}', $value, $this->dane); //W jaki sposob (chyba bedzie potrzeba petla) zrobic zeby //kazda blok byl podmieniany?? $this -> Replace = $file_display; } [/php:1:0cee5d68c0] Może nie wykonuj tego tak w "locie" to nie bedzie potrzebna pętla (IMG:http://forum.php.pl/style_emoticons/default/smile.gif) [php:1:0cee5d68c0]<?php function Content($name, $value) { // Dodaj sobie te 2 var 'y i ustal jakies sensowne nazwy (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg) $this->array[] = $name; $this->array2[] = $value; } [/php:1:0cee5d68c0] Tu wrzucasz sobie dane co ma na co zamienic nastepnie dodajesz 2 funckje do tpl'owania. [php:1:0cee5d68c0]<?php function Tpl() { /* Bedzie dzialac pod warunkiem ze $this->dane to jest zmienna * ktora zawiera ciag (kodu htm) jezeli to tablica to ja poprostu * polacz */ return str_replace('{'.$this->array.'}', $this->array2, $this->dane); } ?>[/php:1:0cee5d68c0] Powinno działać |
|
|
![]() ![]() |
![]() |
Aktualny czas: 15.09.2025 - 21:41 |