Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6384139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:44:17+00:00 2026-05-25T02:44:17+00:00

As of right now I’ve created a template class, and I’ve created a registration

  • 0

As of right now I’ve created a template class, and I’ve created a registration class. But I’m having trouble getting the two to work properly together so that I can display my variables in my template files.

Here are the basics of my template class:

class siteTemplate {
    function getTemplate($file, $varesc=false) {
        if (file_exists("templates/" . $file)) {
            $data = file_get_contents("templates/" . $file);
            $data = str_replace("\"","\\\"", $data);
            $data = str_replace("\'","\\\'", $data);
            $data = str_replace("\\n","\\\n", $data);
            if($varesc)
                $data = str_replace("\$","$", $data);
                return $data;
            } else {
                die("Error.<br />Could not find <strong>" . $file . "</strong>.");
            }
    }
    function createGlobal() {
        global $siteName, $siteUrl;
        global $content;
        eval("\$main = \"".$this->getTemplate("main.html")."\";");
        echo $main;
    }
}

$tp = new siteTemplate();

A function from my registration class:

public function get_username($uid) {
    $result = mysql_query("SELECT username FROM users WHERE uid = $uid");
    $user_data = mysql_fetch_array($result);
    echo $user_data['username'];
}

I can echo out data from my registration class in index.php

echo $user->get_username($uid);

BUT I can’t do the same thing within my template files. What adjustments do I need to make to make this work together. Live example: http://www.aarongoff.com/i
Username: test
Password: test

If you look I’m echoing out “Logged in as: test”
But when I try to call for that variable within my template file it just displays “Logged in as:”

(I know there are SQL vulnerabilities, I’m just testing to get my classes to work)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:44:17+00:00Added an answer on May 25, 2026 at 2:44 am

    The true answer to this is that PHP IS a template! Use pure PHP code as your templates. Then you don’t have to keep reimplementing every one of PHP’s features in your ad hock template class.

    This is called the http://en.wikipedia.org/wiki/Inner-platform_effect and you should avoid it. Just use PHP directly, it’s what it was made for.

    What you should do is be disciplined about naming the PHP files, and separating concepts logically. But don’t try to reimplement PHP in PHP.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Right now I have a function, in a class that is used to listen
Right now any new UIViewController added to my storyboard needs to have a class
Right now I'm doing this: class MyTest(Base): __tablename__ = 'mytest' id = Column(Integer, primary_key
Right now I'm using OleDbDataAdapter objDataReader = new OleDbDataAdapter(); objDataReader.SelectCommand = myCommand; objDataReader.Fill(myDataTable); But
Right now, to be sure I am getting what I want I am using
Right now, I have the following class methods: def check_capacity(self, at_index) def update_capacity(self, at_index)
Right now I have a static class called universe in my ASP.NET application. The
Right now, I have two Eclipse projects - they both use Maven 2 for
Right now I have two regular expressions that does this: Regex-1 = (\\{(\\w+)\\}); Regex-2
Right now I'm asking the user for two numbers. I'm trying to print the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.