Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> ENGINE
eS...
post
Post #1





Grupa: Zarejestrowani
Postów: 367
Pomógł: 2
Dołączył: 4.03.2003
Skąd: C:/Windows/Temp

Ostrzeżenie: (0%)
-----


witam
wiem ze są arty na temat engine, ale szczerze mówiąc to nie zabardzo mi wychodzi czytanie w necie (IMG:http://forum.php.pl/style_emoticons/default/tongue.gif)

ale chodzi mi o to.
1.od strony teorii, o czym sie uczyć, aby w przyszłosci stworzyc swój engine??(klasy i obiekty??)
2.czy mozna skądś sciagnąć gotowy engine??
3. hmmm tutaj zamieszczam podziękowania (IMG:http://forum.php.pl/style_emoticons/default/biggrin.gif)
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
MaKaO
post
Post #2





Grupa: Zarejestrowani
Postów: 70
Pomógł: 0
Dołączył: 3.05.2003
Skąd: Głogów

Ostrzeżenie: (0%)
-----


class.template.php
------------------------------------
[php:1:3ba2db3e88]<?php
class Template {
var $tmpl;
var $dane;
function Template ($name) {
$this->tmpl = implode('', file($name));
$this->dane = Array();
}
function add($name, $value = '') {
if (is_array($name)) {
$this->dane = array_merge($this->dane, $name);
} else if (!empty($value)) {
$this->dane[$name] = $value;
}
}
function execute() {
return preg_replace('/{([^}]+)}/e', '$this->dane["1"]', $this->tmpl);
}
}
?>[/php:1:3ba2db3e88]

test.php
------------------------------------
[php:1:3ba2db3e88]<?php
include 'class.template.php';
$tmpl = new Template('test.tpl');
$tmpl->add('title', 'tytuł strony');
$tmpl->add('autor', 'imie autora');
$tmpl->add('charset', 'iso-8859-2');
$dane = Array('imie'=> 'Marcin', 'podpis'=>'jakiś tam podpis');
$tmpl->add($dane);
echo $tmpl->execute();
?>[/php:1:3ba2db3e88]

test.tpl
------------------------------------
Kod
<html>

<head>

<title>{title}</title>

<meta http-equiv="Content-type" content="text/html; charset={charset}">

</head>

<body>

<p>Autorem strony jest {autor}</p>

<p>Witaj {imie}</p>

<p>{podpis}</p>

</body>

</html>


No to jest taki banalny :-) A jeżeli chodzi o najlepszy system szablonów, to SMARTY. :-)
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 3.10.2025 - 14:09