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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:54:57+00:00 2026-05-24T13:54:57+00:00

Very new to web programming still and I don’t really have a specific question

  • 0

Very new to web programming still and I don’t really have a specific question per se, but I was wondering how close this design is to how an MVC would be implemented under these conditions. Here is the template class that I am using. db.php just connects to the database.

I’d like to stay away from answers like “Use CodeIgniter, CakePHP, Zend Framework, et cetera” because I most likely am going to end up doing that eventually but for now I’d like to understand how to implement a barebones MVC pattern in a typical website using out of the box PHP and HTML. Also, I’ve read the wikipedia page for Model-view-controller and I am still confused as to how to apply it in this circumstance.

I don’t really like the solution I am using right now because it still seems rather unorganized. I’m not sure what exactly I mean but it just seems to smell a bit. With the mass amount of variables it still seems rather messy and inelegant. It seems like many parts of the site struggle for access to other parts and that the overall design is a bit mucky. I am constantly passing large amounts of variables to constructors and the entire solution seems very inflexible. I don’t know; I’m still somewhat confused as to what the controller is in this context or whether or not I even have one. Hopefully someone can alleviate all this confusion x_x

index.php

<?php
require('db.php');
require('header_model.php');
require('submissions_model.php');
require('template.php');

$headerModel = new HeaderModel();
$page = $headerModel->getPage();
$sort = $headerModel->getSort();
$search = $headerModel->getSearch();

$submissionsModel = new SubmissionsModel($sort, $page, $resultsPerPage, $search);
$submissions = $submissionsModel->getSubmissions();
$outcomeCount = $submissionsModel->getOutcomeCount();

$index_view = new Template('index_view.php', array(
    'header' => new Template('header.php'),
    'menu' => new Template('menu.php', array('sort' => $sort)),
    'submissions' => new Template('submissions.php', array('submissions' => $submissions)),
    'pagination' => new Template('pagination.php', array('page' => $page, 'resultsPerPage' => $resultsPerPage, 'outcomeCount' => $outcomeCount, 'sort' => $sort)),
    'footer' => new Template('footer.php')
));

$index_view->render();
?>

index_view.php snippet

<!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">
    <head>
        <title>My Website</title>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
        <link href="styles.css" rel="stylesheet" type="text/css"/>
        <link href="favicon.png" rel="shortcut icon" />
    </head>
    <body>
        <?php
        $this->header->render();
        $this->menu->render();
        $this->submissions->render();
        $this->pagination->render();
        $this->footer->render();
        ?>
    </body>
</html>

header_model.php snippet

public function getSearch() {
    if (isset($_GET['search']))
        return $_GET['search'];
    else
        return '';
}

submissions_model.php snippet

class SubmissionsModel {
    private $sort;
    private $page;
    private $resultsPerPage;
    private $search;

    public $submissions;
    public $outcomeCount;

    public function __construct($sort, $page, $resultsPerPage, $search) {
        $this->sort = $sort;
        $this->page = $page;
        $this->resultsPerPage = $resultsPerPage;
        $this->search = $search;

        $this->initialize();
    }

    private function initialize() {
        $submissionQuery = $this->getSubmissionQuery($this->search);
        $this->outcomeCount = mysql_num_rows($submissionQuery);
        $this->submissions = array();

        while ($row = mysql_fetch_assoc($submissionQuery)) {    
            $voteblock = $this->getVoteblock($row);
            $tags = $this->getTags($row);
            $commentCount = mysql_num_rows(mysql_query("SELECT id FROM comments WHERE submissionID = $row[id]"));
            $this->submissions[] = array('submission' => $row, 'upvote' => $voteblock['upvote'], 'votes' => $voteblock['votes'], 'downvote' => $voteblock['downvote'], 'tags' => $tags, 'commentCount' => $commentCount);
        }
    }
}
  • 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-24T13:54:58+00:00Added an answer on May 24, 2026 at 1:54 pm

    I’ve recently been through this quandary myself and after some trial and error came to the following design pattern implementation which differs slightly from ericacm’s answer:

    1. A Front Controller handles all incoming requests and delegates out to the required Controller. This usually consists of mapping the incoming URL to a file path somehow, but you may also be loading some initial data or base class, or setting up some application environment settings.

    2. Once the Controller is loaded the Front Controller isn’t used again until there is a new request. The (for want of a better word) ‘Main’ Controller now loads any required Model class(es) and calls methods in them to obtain any required data.

    3. The Model has methods to extract and process the requested data from the data sources (i.e. a database). It cannot access anything except for other models and the DB connection.

    4. Once the data has been loaded the Controller loads the relevant View class and ‘pushes’ the data into variables held within the View.

    5. The View class itself has no ‘higher’ logic functions and has no access to the Model or Controller methods. It is really only there to provide methods for processing data into the required output media (i.e. html) through various getSomeVar() or renderSomeData() methods.

    6. Finally the Controller calls the View’s method to render the page, at which point the Controllers job is done. The View will load the necessary template files which will be interpreted to produce the output for the browser.

    7. The template file(s) are mostly structure HTML with no programming logic. The data is only loaded into the page via calls to various renderSomething() methods within the View.

    My thinking behind this was that the Controller should be in control (duh), of everything!

    hth

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

Sidebar

Related Questions

No related questions found

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.