$_GET template system example please

Status
Not open for further replies.

JoshuaLuke

Posting Freak
Jan 29, 2012
529
51
Hey,

So i'm making a template system using $_GET['p'], here's it so far:
PHP:
<?php
## Deny any access
if(!defined('ALLOWED')){exit();}
 
## Begin the class
class template {
 
public function initiate() {
global $CONF;
if(!isset($_GET['p'])) {
header('Location: index.php?p=index');
} else {
include('templates/' . $CONF['site']['template'] . '/' . $_GET['p'] . '.php');
}
}
}
?>
How would I put $this->set('key', 'value'); in the constructor function so it corresponds into any template? I tried a few things but couldn't get it to work. I've never worked with $_GET template systems before so help is good.
 
Jan 17, 2012
649
166
I think this is what you're looking for?
PHP:
<?php
class Template
{
    public $param = array();
 
    function __construct()
    {
        $this->set('hi', 'hello');
    }
 
    public function set($key, $value)
    {
        $this->param[$key] = $value;
    }
   
    public function filter($str)
    {
        foreach($this->param as $key => $value)
        {
            $str = str_replace('[' .$key. ']', $value, $str);
        }
       
        return $str;
    }
}
?>
I don't really get what you're looking for.
 

IntactDev

Member
Nov 22, 2012
399
71
Take a look at mine; it's kinda sloppy, but I don't revamp/clean my code till I'm done:

AN0UQW.PNG
 
Status
Not open for further replies.

Users who are viewing this thread

Top