[PHPTAL] Using PHPTAL with index.php?page=... thing
Kornel Lesinski
kornel at aardvarkmedia.co.uk
Mon Jan 21 12:21:18 CET 2008
On Mon, 21 Jan 2008 09:12:48 -0000, Anton Andrievskij <x.meglio at gmail.com>
wrote:
> I write this letter to ask about what the best idea about how to use the
> PHPTAL engine with
> the standard PHP site engine technology like this:
>
> www.mysite.com/index.php?page=login
> www.mysite.com/index.php?page=faq
> www.mysite.com/index.php?page=subscrib
> and so on...
>
> I'm going to build index.html template and run it from index.php page,
> but then I have different code to be executed on different pages like
> login.php,
> faq.php, subscribe.php and so on.
PHPTAL works best if you design your application using MVC pattern
(separate data, application logic and presentation layers).
However, if you're looking for a simple approach:
You probably have index.php file with something like:
include "pages/$page.php"; // ofcourse $page should be throughly filtered
to avoid security issues
Then change it to:
$phptal = new PHPTAL("templates/$page.html");
include "pages/$page.php";
echo $phptal->execute();
and inside page's php files (like faq.php) collect data in arrays or
directly in $phptal object.
Instead of outputting everything instantly, e.g.:
foreach($questions as $question) {echo '<h2>'.$question.'</h2>';}
just save data for later use in a template:
$phptal->questions = $questions;
--
regards, Kornel
More information about the PHPTAL
mailing list