![]() |
![]() ![]() |
![]() |
![]()
Post
#1
|
|
Grupa: Zarejestrowani Postów: 48 Pomógł: 0 Dołączył: 28.02.2010 Ostrzeżenie: (0%) ![]() ![]() |
a wiec tak
zrobilem swoj template engine z cache mozna wkladac do plikow szablonu zmienne i robic ify i mam taka funkcje w klasie: Kod public function show($file) { if (!file_exists($this->cache_dir."cache.".$file)) { $sname = basename($_SERVER['SCRIPT_FILENAME']); echo("<b>TemplateEngine Error:</b> File <b>".$this->template_dir.$file."</b> doesn't exist. Error in <b>".$sname."</b>.<br />"); return 0; } include($this->cache_dir."cache.".$file); } i jak uzywam np: show("index_body.php"); to pojawia sie tresc pliku ale zmienne z index.php nie chodza jak to mozna naprawic? |
|
|
![]()
Post
#2
|
|
Grupa: Zarejestrowani Postów: 511 Pomógł: 143 Dołączył: 13.03.2010 Skąd: Jasło Ostrzeżenie: (0%) ![]() ![]() |
pokaż ten plik index.php i index_body.php
|
|
|
![]()
Post
#3
|
|
Grupa: Zarejestrowani Postów: 48 Pomógł: 0 Dołączył: 28.02.2010 Ostrzeżenie: (0%) ![]() ![]() |
INDEX.PHP
Kod <?php include("template.php"); $logged = 1; $t = new template; $t->template_dir("templates/"); $t->cache_dir("cache/"); $t->convert("index_body.php"); $t->show("index_body.php"); ?> INDEX_BODY.PHP Kod {if=$logged == 0/} lol {elseif=$logged == 1/} lol2 {/if} //edit: dalem $logged = 1; tylko do testow bo to nie jakis duzy moj skrypt tylko tescik template engina mojego i pojawia sie lol zamiast lol2 Ten post edytował DowNlOaD_ 28.05.2010, 18:20:15 |
|
|
![]()
Post
#4
|
|
Grupa: Moderatorzy Postów: 4 069 Pomógł: 497 Dołączył: 11.05.2007 Skąd: Warszawa ![]() |
A gdzie przekazujesz zmienne do funkcji ?
|
|
|
![]()
Post
#5
|
|
Grupa: Zarejestrowani Postów: 48 Pomógł: 0 Dołączył: 28.02.2010 Ostrzeżenie: (0%) ![]() ![]() |
zmienne normalnie chodza
moze dam template.php? bo do konca nie rozumiem cie Kod <?php class template { protected $template_dir; protected $cache_dir; protected $values = array(); public function template_dir($template_dir) { $this->template_dir = $template_dir; } public function cache_dir($cache_dir) { $this->cache_dir = $cache_dir; } public function setvar($key, $value) { $this->values[$key] = $value; } public function convert($file) { if (!file_exists($this->template_dir.$file)) { $sname = basename($_SERVER['SCRIPT_FILENAME']); echo("<b>TemplateEngine Error:</b> File <b>".$this->template_dir.$file."</b> doesn't exist. Error in <b>".$sname."</b>.<br />"); return 0; } if (!file_Exists($this->cache_dir."cache.".$file)) { $output = file_get_contents($this->template_dir.$file); foreach ($this->values as $key => $value) { $replacement = "{".$key."}"; $output = str_replace($replacement, $value, $output); } $replacement = "{if="; $replaced = "<?php if("; $output = str_replace($replacement, $replaced, $output); $replacement = "/}"; $replaced = ") { ?>"; $output = str_replace($replacement, $replaced, $output); $replacement = "{elseif}"; $replaced = "<?php } else { ?>"; $output = str_replace($replacement, $replaced, $output); $replacement = "{elseif="; $replaced = "<?php } else if("; $output = str_replace($replacement, $replaced, $output); $replacement = "{/if}"; $replaced = "<?php } ?>"; $output = str_replace($replacement, $replaced, $output); $fp = fopen($this->cache_dir."cache.".$file, "w+"); fwrite($fp, $output); fclose($fp); } } public function show($file) { if (!file_exists($this->cache_dir."cache.".$file)) { $sname = basename($_SERVER['SCRIPT_FILENAME']); echo("<b>TemplateEngine Error:</b> File <b>".$this->template_dir.$file."</b> doesn't exist. Error in <b>".$sname."</b>.<br />"); return 0; } include($this->cache_dir."cache.".$file); } } ?> i co o tym sadzicie? |
|
|
![]()
Post
#6
|
|
Grupa: Moderatorzy Postów: 4 069 Pomógł: 497 Dołączył: 11.05.2007 Skąd: Warszawa ![]() |
Czy ty zrozumiałeś co ja napisałem? Nie przekazujesz zmiennych do funkcji/metody w której includujesz szablon...
|
|
|
![]()
Post
#7
|
|
Grupa: Zarejestrowani Postów: 2 291 Pomógł: 156 Dołączył: 23.09.2007 Skąd: ITALY-MILAN Ostrzeżenie: (10%) ![]() ![]() |
Nie sprawdzalem ale ten str_replace() mnie nie przekonowywuje do konca, do takiego czegos uzywa sie regexp :]
Bo str_replace nie uwzgledni ci wzorca w 100% |
|
|
![]()
Post
#8
|
|
Grupa: Zarejestrowani Postów: 48 Pomógł: 0 Dołączył: 28.02.2010 Ostrzeżenie: (0%) ![]() ![]() |
no niewiem ;p
mi jakos all chodzi i konwertuje all a jak chce uzyc show aby potem includowalo plik z cache to zmiennych z index.php jakos nie wykrywa ;/ a jak poprostu uzyje: Kod include("cache/cache.index_body.php"); to all chodzi ale po to zrobilem show() aby skrocic kod a zmiennych z klasy nie moge wyciagnac do include, chyba ze sie da i niewiem jak ;/ //edit SOLVED (IMG:style_emoticons/default/smile.gif) moze byc lock ;p Ten post edytował DowNlOaD_ 28.05.2010, 18:40:45 |
|
|
![]()
Post
#9
|
|
Grupa: Zarejestrowani Postów: 511 Pomógł: 143 Dołączył: 13.03.2010 Skąd: Jasło Ostrzeżenie: (0%) ![]() ![]() |
|
|
|
![]() ![]() |
![]() |
Aktualny czas: 24.08.2025 - 15:59 |