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 6891631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:26:03+00:00 2026-05-27T06:26:03+00:00

Well, my question is very simple but a little hard to accept the solution,

  • 0

Well, my question is very simple but a little hard to accept the solution, but anyway .. is the following, I have a ‘mini-framework‘, something to work on writing up of a single scheme, helps me a lot, accelerate work on some things, however, the question is even with the view, in a way, using a scheme of templates is very easy and also very interesting because when you have to change anything related to visualization, the template changes only, but then, in time to render this template, which is the best way? I’m currently working this way:

<?php

          class View {

                 private $vars;

                 public function __get ( $var ) {
                        if ( isset( $this->vars [ $var ] ) ) {
                               return $this->vars[ $var ];
                        }
                 }

                 public function assign ( $var , $value ) {
                        $this->vars [ $var ] = $value;
                 }

                 public function show ( $template ) {
                        include_once sprintf ( "%s\Templates\%s" , __DIR__ , $template ) ;
                 }

          }

It is not the complete code, I am building structures and reviewing the scheme yet, so I do the following ..

<?php
          require_once 'MVC/Views/View.php';
          $View = new View ( ) ;

          $View->assign( 'title' , 'MVC, View Layer' ) ;
          $View->show ( 'test.phtml' );

And the template

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
       <head>
              <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
              <title><?php echo $this->title ?></title>
       </head>
       <body>

       </body>
</html>

The output is correct, all working as expected, but my question is: is this the best way to do? including the file and letting the play interprets the code written in .phtml

  • 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-27T06:26:04+00:00Added an answer on May 27, 2026 at 6:26 am

    In many frameworks I saw this kind of statements:

    public function show ( $template ) {
      ob_start();
      require sprintf ( "%s\Templates\%s" , __DIR__ , $template ) ;
      return ob_get_flush();
    }
    

    Using the output buffer you can have the template evaluated to a string instead of directly sent in the output. This can come handy when you need to change headers after evaluating the template or to make post-processings.

    Using require instead of include_once will allow you to render the same template more times (e.g. if you want to have some kind of templates composition) and to get an error if the template file is not found (include doesn’t give an error in that situation).

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

Sidebar

Related Questions

This is likely a very simple question with a straightforward answer but I'm something
I have few very simple question. I searched a web for them, but I
I have a question about DFA minimization. So I've used very well known techniques
Well looks too simple a question to be asked but i asked after going
Well, very simple question. So that's good news for you, I guess. More thorough
The following code is pretty self-explanatory and my question is very simple : Why
I'm building a simple project something like Twitter but very simple :) There are
I have a very simple question. Is there any way to relate database errors
I have a very simple CSS related question on iPad. I have a set
Very simple question but all the answer I read over the web doesn't apply.

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.