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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:54:40+00:00 2026-05-12T23:54:40+00:00

I dont understand what the layout is, in the view. I asked a question

  • 0

I dont understand what the layout is, in the view. I asked a question previously on the subject of templating in PHP, but I still dont quite understand. I assume that you create a general layout for the site and then include each specific view within that layout…. I would like to know how to go about doing this. Also, are should the templates be made using just html, because I also looked at these things called helpers…. I’m just confused on the View part of the MVC, and the actual templates and how they’re made. I learn best with examples, If you guys have any.

Also, a more important question, lets say I had a form that a user saw only if he was logged in, would I control that in the view, or in the controller?

So Would i do

in the controller

include 'header';
if(isset($_SESSION['userID'])){
    include 'form';
}
include 'footer';

or

in the template

<html>
<?php if(isset($_SESSION['user_id'])): ?>
  <form>....</form>
<?php endif;?>
</html>

EDIT

So, is there an include statement from within the layout to see the specific view template? how so?

  • 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-12T23:54:41+00:00Added an answer on May 12, 2026 at 11:54 pm

    I hesitate to answer this question only because of the religious fervor that surrounds it.

    To get a really good understanding of the issues behind the general concepts see This Wiki Discussion Page This is the discussion page around the wiki MVC article.

    Here is the rule of thumb I like to follow (BTW I use CodeIgniter and it kind of sounds like you are too):

    The “view” should have virtually no logic. It should only be HTML (in the web world) with peppered PHP that simply echos variables. In your example you would break out the form into its own view and the controller would determine if was loaded or not.

    I like to look at it this way: The view should have no concept of where the data comes from or where it is going. The model should be view agnostic. The controller meshes data from the model and provides it to the view – and it takes input from the view and filters it to the model.

    Here is a quick and dirty (untested – but it should get the point across) example:

    Theapp.php (The App controller)

    class Theapp extends Controller
    {
       var $_authenticated;
       var $_user;
       var $_menu; // array of menus
    
       function __construct()
       {
          session_start();
          if (isset($_SESSION['authenticated']) && $_SESSION['authenticated'])
          {
               $this->_authenticated = $_SESSION['authenticated'];  // or some such thing
               $this->_user = $_SESSION['user'];
          }
          $this->_menu = array("Logout", "Help", "More");
          parent::__construct();
          $this->loadView("welcome"); // loads primary welcome view - but not necessarily a complete "html" page
       }
    
    
       function index()
       { 
          if (!$this->_authenticated) 
             $this->loadView("loginform");
          else
          {
             $viewData['menu'] = $this->_menu;
             $viewData['user'] = $this->_user;
             $this->loadView("menu", $viewData);
          }
       }
    
    
       function login()
       {
          /* code to authenticate user */
       }
    
       function Logout() { /* code to process Logout menu selection */ }
       function Help() { /* code to process Help menu selection */ }
       function More() { /* code to process More menu selection */ }
    }
    

    welcome.php

    <h1> Welcome to this quick and dirty app!</h1>
    All sorts of good HTML, javascript, etc would be put in here!
    

    loginform.php

    <form action"/Theapp/login" method="post">
       User: <input id='user' name='user'>
       Pass: <input id='pass' name='pass' type='password'>
       <input type='submit'>
    </form>
    

    menu.php

    Hi <?= $user ?>!<br>
    Here's your menu<br>
    <? foreach ($menu as $option) { ?>
    <div class='menuOption'><a href='/Theapp/<?=$option?>'><?=$option?></a></div>
    <? } ?>
    

    Hope this helps.

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

Sidebar

Related Questions

This code works, but i dont understand why. With DeferredLoadingEnabld = false, I would
I don't understand why IList implements IEnumerable taking in consideration that IList implements ICollection
It seems I don't understand javascript callbacks quite as well as I thought. In
I'm trying to center a View vertically on screen with the following layout: <?xml
I don't understand where the extra bits are coming from in this article about
I don't understand it. The ids of html elements in the master page are
I don't understand how GCC works under Linux. In a source file, when I
I don't understand, why does the following regular expression: ^*$ Match the string 127.0.0.1?
I don't understand why one method would work and the other would throw a
I don't understand what could be the uses of lvalue subroutines? What is it

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.