[PHP] Template Parsing

Status
Not open for further replies.

brsy

nah mang
May 12, 2011
1,530
272
I am attempting to create a system similar to the one on RevCMS, but I am having a slight issue. I know it's close to completion, but I am receiving a ridiculous error.

Global.php
PHP:
<?php
/***************************************************************\
+ TwiztCMS - "Twizting" the standards of CMS'
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ @Copyright Information
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ Copyright (C) 2012 to Chris 'Twizt' Davis
+ TwiztCMS is licensed under the Public GNU v2 license
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ @License Information
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ LICENSE TEXT GOES HERE
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ @Author Information                       
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ Otaku-Studios & DevBest - Twizt
+ ***** - zTriick
+ MSN - [email protected]
+ Website - zTriick.com & Pabbo.NET
\***************************************************************/
 
require_once('class/class.configuration.php');
require_once('class/class.module.php');
require_once('class/class.param.php');
 
$tCore = new tCore();
$tpl = new tpl();
 
        $this->params['siteLink'] = $_CONFIG['Site']['Link'];
        $this->params['siteName'] = $_CONFIG['Site']['Name'];
?>

class.tpl.php
PHP:
<?php
/***************************************************************\
+ TwiztCMS - "Twizting" the standards of CMS'
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ @Copyright Information
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ Copyright (C) 2012 to Chris 'Twizt' Davis
+ TwiztCMS is licensed under the Public GNU v2 license
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ @License Information
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ LICENSE TEXT GOES HERE
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ @Author Information                       
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ Otaku-Studios & DevBest - Twizt
+ ***** - zTriick
+ MSN - [email protected]
+ Website - zTriick.com & Pabbo.NET
\***************************************************************/
 
class tpl {
    public function SetParam($str, $param) {
        $this->params[$param] = $value;       
    }
   
    function FilterParams($str)
    {
        foreach ($this->params as $param => $value)
        {
            if (is_object($value))
            {
                continue;
            }
       
            $str = str_ireplace('%' . $param . '%', $value, $str);
        }
       
        return $str;
    }
}
?>

Error:
xmsfdY.png

 

Kryptos

prjRev.com
Jul 21, 2010
2,205
1,252
facepalm.jpg x 9001

The error pretty much explains itself, '$this' equals to the class object you're currently in, and there you're not inside a class.

You would change $this->params for $tpl->params, but I think that's also pretty stupid since you have a SetParam function, use that.
 
  • Like
Reactions: Ept

brsy

nah mang
May 12, 2011
1,530
272
facepalm.jpg x 9001

The error pretty much explains itself, '$this' equals to the class object you're currently in, and there you're not inside a class.

You would change $this->params for $tpl->params, but I think that's also pretty stupid since you have a SetParam function, use that.
But, I actually did both of those and it didn't work. I firstly tried $tpl, that's why I had

$tpl = new tpl();
 

Kryptos

prjRev.com
Jul 21, 2010
2,205
1,252
But, I actually did both of those and it didn't work. I firstly tried $tpl, that's why I had

$tpl = new tpl();

I'm not spoon feeding you, you already copied most of Rev's class, only that you forgot a tiny bit. Plus, you aren't using the SetParam method like I just told you.

Plus, I don't see where you're testing it.. Do you have an HTML file or something? You need to parse it to filterParams...

Anyways, if you come up with something original, I'll help you. Just do a little effort.
 

brsy

nah mang
May 12, 2011
1,530
272
I'm not spoon feeding you, you already copied most of Rev's class, only that you forgot a tiny bit. Plus, you aren't using the SetParam method like I just told you.

Plus, I don't see where you're testing it.. Do you have an HTML file or something? You need to parse it to filterParams...

Anyways, if you come up with something original, I'll help you. Just do a little effort.
Well, I don't even have RevCMS downloaded to this computer, nor any of my VPS'.
Plus, I am referring to the system in fCMS. I am using it as a reference, just for learning purposes.
 

Joopie

Active Member
Sep 13, 2011
135
65
/facepalm

PHP:
$tpl = new tpl();
 
        $this->params['siteLink'] = $_CONFIG['Site']['Link'];
        $this->params['siteName'] = $_CONFIG['Site']['Name'];

to

PHP:
$tpl = new tpl();
 
        $tpl->params['siteLink'] = $_CONFIG['Site']['Link'];
        $tpl->params['siteName'] = $_CONFIG['Site']['Name'];

-----

PHP:
public function SetParam($str, $param) {
        $this->params[$param] = $value;     
    }

to

PHP:
public function SetParam($str, $param) {
        $this->params[$param] = $str;     
    }

----

add in tpl class

PHP:
public $params = array()

------

Did you even test it? and do you even know what you're doing?
 
Status
Not open for further replies.

Users who are viewing this thread

Top