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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:50:09+00:00 2026-05-14T21:50:09+00:00

I’m about to do a PHP website using the MVC pattern. I am not

  • 0

I’m about to do a PHP website using the MVC pattern. I am not using a framework as the site is fairly simple and I feel that this will give me a good opportunity to learn about the pattern directly. I have a couple questions.

Question 1: How should I organize my views? I’m thinking of having a Page view which will have the header and footer, and which will allow for a Content view to be nested between them.

Question 2: If I have 5 Content pages, should I make 5 different views that can be used as the content that is nested within the Page view? Or, should I make them all extend an abstract view called AbstractContent?

Question 3: What about controllers? I think there should be one main controller at least. But then where does the request go from there? To another controller? Or should I just call the Page view and leave it at that? I thought that controllers were supposed to handle input, possibly modify a model, and select a view. But what if one of the views nested within the view that a controller calls requires additional input to be parsed?

Question 4: Are controllers allowed to pass parameters into the view? Or should the controller simply modify the model, which will then affect the view? Or is the model only for DB access and other such things?

  • 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-14T21:50:10+00:00Added an answer on May 14, 2026 at 9:50 pm

    1 – This is a matter of preference. The simplest way would be to have a separate header and footer file. Then you could do something like this in your page controller

    $title="Page Title";
    $var1 = 'var1';
    $var2 = 'var2';
    $var3 = array("asdf","adsfasdf","234");    
    
    include(HEADER); //$title is in header
    include(DIR_VIEWS . 'page.php'); //$var1/2/3 are in page.php
    include(FOOTER);
    
    // variable were created before pages were included so they will be set in the templates
    

    If you were to go the nested route you would have to start fiddling with str_replace and that starts heading towards a template engine, out of scope for this answer.

    2 – No need to make views objects. A “view” can just be a file on your filesytem that contains the html for that view. Like my example above. These pages can contain basic php to loop/echo variables as well.

    3 – You are describing a front controller (sometimes called dispatcher or router). This is really the way to go. There are a couple methods for creating a front controller.

    You can have an array of urls that point to controllers.

    $routes = array (
    
        '~^/home/$~' => 'home.php',
        '~^/contact/$~' => 'contact.php',
        '~^/blog/.*?$~' => 'blog.php'
    
    );
    

    or you can use the first “directory” in the url as the controller name and load that file form your controller directory.

    4 – The entire point of the controller is to get info from the model and pass the data to the view.


    Edited for comment


    If you want a bunch of views to have a sidebar you just include that view in the other view. For example:

    <div id="content">
        <p>lorem ispum stuff</p>
    </div>
    <?php include(DIR_VIEWS . 'sidebar.php');
    

    Just make sure that in controllers that “control” pages with sidebars you include some code for sidebar functions:

    if ( $_GET['keywords'] ) {
        $sidebar_search_results = get_search_results($_GET['keywords']);
    }
    // this code should be in a file that you include
    

    $sidebar_search_results could be an array of results that your sidebar view parses and displays.

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

Sidebar

Ask A Question

Stats

  • Questions 432k
  • Answers 432k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This transformation: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output omit-xml-declaration="yes" indent="yes"/> <xsl:strip-space elements="*"/>… May 15, 2026 at 2:34 pm
  • Editorial Team
    Editorial Team added an answer You can use GetDriveType to get the basic interface type(ie:… May 15, 2026 at 2:34 pm
  • Editorial Team
    Editorial Team added an answer schedtool -a 0x1 -e program1 schedtool -a 0x1 -e program2… May 15, 2026 at 2:34 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.