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

  • Home
  • SEARCH
  • 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 9174989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:50:31+00:00 2026-06-17T16:50:31+00:00

I made a basic PHP template system made of controllers/pages.php and views/pages.php . The

  • 0

I made a basic PHP template system made of controllers/pages.php and views/pages.php. The views uses the controller to populate the HTML with data that should be coming from the controller, however some data is not being passed from controller to views I marked the code below with comments as such “# ==> NOT WORKING” anything with such comment does not return any data to views any suggestion as to possibly why?

<?php

# THIS IS CONTROLLERS/PAGES.PHP

class Page {
    private $title, $stylesheets=array(), $javascripts=array(), $body;

    # ==> NOT WORKING
    function Site() {
        $site = "http://dev.site.tld/";
        return $site;
    }

    function Page() {
        $this->addCSS('css/main.css');
        $this->addCSS('css/font-awesome.css');
        $this->addJavascript('js/jquery.js');
        $this->addJavascript('js/application-build102121.js');
    }

    function setTitle($title) {
        $this->title = $title;
    }

    # ==> NOT WORKING
    function setCopyright() {
         $copyright_year = date("Y");
         return $copyright_year;
    }

    # ==> NOT WORKING
    function setAppName() {
         $app_name = "Latte";
         return $app_name;
    }

    function addCSS($path) {
        $this->stylesheets[] = $path;
    }

    # ==> NOT WORKING
    function listCSS($path) {   
        $data = Site(); 
        foreach ($this->stylesheets as $stylesheet) {
             echo '<link href="' . $data . $stylesheet . '" rel="stylesheet" type="text/css" />' . "\n";
        }
        return $this;   
    }

    # ==> NOT WORKING
    function listJS($path) {
        $data = Site();
        foreach ($this->javascripts as $javascript) {
             echo '<script src="' . $data . $javascript . '" type="text/javascript" defer="defer"></script>' . "\n";
         }  
        return $this;
    }

    function addJavascript($path) {
        $this->javascripts[] = $path;
    }


    function startBody() {
        ob_start();
    }

    function endBody() {
        $this->body = ob_get_clean();
    }

    function render($path) {
        ob_start();
        include($path);
        return ob_get_clean();
    }
}

Error_Reporting returns

Notice: Undefined property: Page::$listCSS in /home/adminis1/public_html/dev/views/pages.php on line 15

Notice: Undefined property: Page::$listJS in /home/adminis1/public_html/dev/views/pages.php on line 17

Notice: Undefined property: Page::$setCopyright in /home/adminis1/public_html/dev/views/pages.php on line 25

The way data is called
Index.php

<?php
require_once('controllers/pages.php');
$page = new Page;
$page->setTitle('Home');
$page->startBody();
?>

<img src="test-img.jpg" />

<?php
$page->endBody();
echo $page->render('views/pages.php');

VIEWS/PAGES.PHP

<?php error_reporting(E_ALL); ?>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title><?php echo $this-setAppName; ?> - <?php echo $this->title; ?></title>

    <!-- view port meta -->
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">


    <!--[if lt IE 9]>
        <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->

    <?php echo $this->listCSS; ?>

    <?php echo $this->listJS; ?>

</head>
<body>

    <?php echo $this->body; ?>

    <footer>
        <p>Copyright &copy; <?php echo $this->setCopyright; ?> </p>
    </footer>

</body>
</html>
  • 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-06-17T16:50:32+00:00Added an answer on June 17, 2026 at 4:50 pm

    You are calling methods like it were properties.

    Change $this->setCopyright to $this->setCopyright() and so on.

    class Page {
        private $title;
    
        function setCopyright() {
            ...
        }
    }
    
    $page = new Page();
    

    $title is a property, access it through $page->title.
    setCopyright() is a function, access it through $page->setCopyright() (with the brackets).

    By the way, use function __construct() when defining an object constructor, it’s better than using function Page().

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

Sidebar

Related Questions

I made a PHP site that uses MySQLi with basic functionality to submit an
I've made a basic HTML5/JS comic creation tool that uses the canvas element. I
I'm creating my own template engine using PHP. The basic idea is that for
I've made a basic looking PHP file load system, so far I can upload
My permalink structure is set so I have url.com/page I made a basic PHP
I made a very basic dictionary that just stores a username in it, and
i have an editor that is basic microsoft actions: createlink bold etc. i made
I'm fairly new to OOP in PHP, I've made a couple of basic scripts
I made a Local Web Game using Javascript and a very basic html page
I know a bit of PHP and so also HTML/CSS, and I have made

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.