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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:30:49+00:00 2026-06-10T16:30:49+00:00

So I’ve been researching and working on building my own MVC framework but keep

  • 0

So I’ve been researching and working on building my own MVC framework but keep running into 6 different ways of implementing it and I’d like to know if I’m on the right track with what I have so far. And yes, I know I could use Zend or others like it but I really want to learn how frameworks work and not just use someone else’s.

Here is a simple version of my index file:

if(isset($_GET['url']))
{
    $url = strtolower($_GET['url']);
}
else
{
    $url = 'home';
}

switch($url)  // Select the controller based on the GET var in the url
{
    case 'home': include(ROOT_DIR . 'app/controllers/homeCon.php'); // This page has the link to the DB test page on it
        break;
    case 'dbtest': include(ROOT_DIR . 'app/controllers/dbTestCon.php');
        break;
    default: include(ROOT_DIR . 'app/views/error404View.php');
}

Here is a simple version of my dbTestCon.php controller:

if(isset($_POST['dbSubBtn']))
{
    $model = new DbTestModel();

    if($_POST['firstName'] != '' && $_POST['lastName'] != '')
    {
        $model->submitToDb($_POST['firstName'], $_POST['lastName'])
        $model->displayPage('goodToGo');
    }  
    else
    {
        $model->displayPage('noInput');
    }
}
else
{
    $model->displayPage('normal');
}

Here is my DbTestModel.php:

class DbTestModel
{
    public function displayPage($version)
    {
        $title = "DB Test Page";
        $themeStylesheetPath = 'public/css/cssStyles.css';

        include(ROOT_DIR . 'app/views/headerView.php');
        include(ROOT_DIR . 'app/views/dbTestView.php');

        switch($version)
        {
            case 'goodToGo':
                include(ROOT_DIR . 'app/views/dbTestSuccessView.php');
                break;
            case 'noInput':
                include(ROOT_DIR . 'app/views/noInputView.php');
                break;
        }
        include(ROOT_DIR . 'app/views/footerView.php');
    }

    public function submitToDb($firstName, $lastName)
    {
        try 
        {
            $db = new PDO("mysql:host=" . DB_HOST . ";dbname=" . DB_NAME, DB_USER, DB_PASS); 
            $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 

            $sql = $db->prepare('insert into dbtest(firstName, lastName) values(:firstName, :lastName)');
            $sql->bindParam(':firstName', $firstName);
            $sql->bindParam(':lastName', $lastName);
            $sql->execute();
            $db = null;
        }
        catch(PDOException $e)
        {
            echo "It seems there was an error.  Please refresh your browser and try again. " . $e->getMessage();
        }
    }
}

And here is my dbTestView.php:

<form name="dbTestForm" id="dbTestForm" method="POST" action="dbtest">
    <label for="firstName">First Name</label>
    <input type="text" name="firstName" id="firstName" />
    <label for="lastName">Last Name</label>
    <input type="text" name="lastName" id="lastName" />
    <input type="submit" name="dbSubBtn" id="dbSubBtn" value="Submit to DB" />
</form>

This simple example works in my testing environment but I’m worried I’ll start using it on my next project and realize half way into it that there is something fundamentally wrong with my framework and have to start over again. Thank you for any help or advice.

  • 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-10T16:30:51+00:00Added an answer on June 10, 2026 at 4:30 pm

    It’s usually considered bad form to do both data storage (e.g Model logic) and output (e.g View logic) in the same place, which is happening in DbTestModel.

    There’s an absolute tonne of refactoring you could do, but I ain’t gonna spell it out for you because I’d end up writing paragraphs.

    I’d urge you to read Fabien Potiencer’s blog series Create your own framework… on top of the Symfony2 Components.

    Even if you don’t want to use his components to help build anything, it should give you a heap of good ideas.

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am currently running into a problem where an element is coming back from
I've tracked down a weird MySQL problem to the two different ways I was
I have a jquery bug and I've been looking for hours now, I can't
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
This could be a duplicate question, but I have no idea what search terms
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.