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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:55:16+00:00 2026-05-20T02:55:16+00:00

I am trying to build a nice PHP framework for personal use. I realize

  • 0

I am trying to build a nice PHP framework for personal use. I realize there are many existing but this is a great learning experience that covers a vast majority of different challenges and really teaches me a lot, as well as having a finished product when i’m done that I can hopefully use to develop other projects from and since I am building it, there should be no learning curve on how to use it.

Some of the basic goals,
– Use PHP Object Oriented instead of procedural.
– Use an MVC or something similar to learn more about this style.
– Be lightweight and fast/good performance

Here is my planned site structure, excluding some other folders for javascript, images, css, some helper functions/files, etc.

///////////// Site structure /////////////

site.com/
        /index.php
site.com/library/
                /Config.class.php
                /Photos.class.php
                /Mail.class.php
                /Filter.class.php
                /QRcodes.class.php
                /Router.class.php
                /Database.class.php
                /Templates.class.php
                /etc, etc,etc......
site.com/modules/
                /account/
                        /model
                        /views
                        /controllers
                /users/
                        /model
                        /views
                        /controllers
                /messages/
                        /model
                        /views
                        /controllers
                /API/
                        /model
                        /views
                        /controllers
                /forums/
                        /model
                        /views
                        /controllers
                /blogs/
                        /model
                        /views
                        /controllers
               /etc, etc, etc, etc.............
                        /model
                        /views
                        /controllers

I have decided to route all Request through a single point of entry, index.php
I will build a Router class/object that will match the URI against a map of possible destinations using regular expressions. Here is a snippet of what I have for now for this part…

<?php
//get url from URL
$uri = isset($_GET['uri']) ? $_GET['uri'] : null;

$uri_route_map = array( 
    //users/account like http://mysite.com/users/324 (any digit)
    'users/friends/page-(?<page_number>\d+)' => 'modules/users/friends/page-$1',
    'users/friends/edit/page-(?<page_number>\d+)' => 'modules/users/friends/edit/page-$1',
    'users/friends/edit' => 'modules/users/friends/edit',
    'users/friends/' => 'modules/users/friends/',
    'users/online' => 'modules/users/online/' ,
    'users/online/page-(?<page_number>\d+)' => 'modules/users/online/page-$1',
    'users/create' => 'modules/users/create',
    'users/settings' => 'modules/users/settings',
    'users/logout(?<page_number>\d+)' => 'modules/users/logout',
    'users/login' => 'modules/users/login',
    'users/home' => 'modules/users/home',

    //forums
    'forums/' => 'modules/forums/index',
    'forums/viewthread/(?<id_number>\d+)' => 'modules/forums/viewthread/$1',
    'forums/viewforum/(?<id_number>\d+)' => 'modules/forums/viewforum/$1',
    'forums/viewthread/(?<id_number>\d+)/page-(?<page_number>\d+)' => 'modules/forums/viewthread/$1/page-$2',
    'forums/viewforum/(?<id_number>\d+)/page-(?<page_number>\d+)' => 'modules/forums/viewforum/$1/page-$2',

    // TESTING new method to define class and page better!
    'users/home' => array('PAGE CLASS NAME', 'ACTION NAME')

    //blog routes coming soon
    //mail message routes coming soon
    //various other routes coming soon
);

//////////////////////////////////
class Router
{
    public function __construct()
    {
    }

    public function get_route($uri, array $uri_routes)
    {
        foreach ($uri_routes as $rUri => $rRoute) {
            if (preg_match("#^{$rUri}$#Ui", $uri, $uri_digits)) {
                //if page number and ID number in uri then set it locally
                $page_number = (isset($uri_digits['page_number']) ? $uri_digits['page_number'] : null);
                $id_number = (isset($uri_digits['id_number']) ? $uri_digits['id_number'] : null);
                echo '<hr> $page_number = ' . $page_number . '<BR><hr> $id_number = ' . $id_number;
                $uri = preg_replace("#^{$rUri}$#Ui", $rRoute, $uri);
                echo '<BR><BR>Match found: ' . $uri_routes . '<BR><BR>';
                break;
            }
        }
        $uri = explode('/', $uri);
    }
}

$uri = new Router();
$uri = $uri->get_routes($_GET['uri'], $uri_route_map);

?>



PLEASE NOTE

THE CODE ABOVE IS ALL TEST CODE AND WILL BE CHANGED, IT IS JUST THE CONCEPT

So as you can see I am planning to have index.php get the URI, check it against valid paths, if one is found, it will include or build a header section, then will build the content section, then finally the footer section of the page.

If you were to access for example… http://www.test.com/blogs/userid-32423/page-23

The the page would…

  • build header()
  • create object blogs… $blogs = new Blogs;
  • call $blogs->viewbyID($userID,$paging); //$userID would be 32423 and $paging would be 23 from the URI
  • build footer section

Now based on my folder structure. I believe that the blogs class file in our above example would be considered the CONTROLLER. If I am correct so far, then this blogs class which is calling blogs->viewbyID(ID,PAGE) the viewbyID method would set up some code, query the database and set up some variables for the page and then it could include a blogs template file. This blogs template file could be considered the VIEWS.

Now I might have this whole concept wrong, and that is why I posted so much code and text to try and explain my outlook on it, please give me thoughts, suggestions, tell me where im completely wrong, and where I might be on the right track, I will greatly appreciate any constructive critism or thoughts. If I am right in my above usage of the View, Controller portion of the MVC pattern, then what part of my code would be considered the Modal? This is somewhat confusing to me for some reason.

Bonus question… What about form post, where should I process these at? In my example I am focusing on the blog module, so lets say POST for adding new blog entry and POST for editing blog entry, where should these be processed (modal, view, controller)?

  • 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-20T02:55:16+00:00Added an answer on May 20, 2026 at 2:55 am

    The controller’s job is to examine the user’s input and determine what is being requested. Once that’s determined, the model(s) is invoked. The controller then takes the model’s payload and gives it to the view.

    Basically, the model is a model of the business. Want to add a blog post? Then the Blog model will have a ->add or ->save method (which is called by the controller. The blog controller may also have an add method, but it is not for talking to the database. It’s for examining the input and then calling the model to do the actual saving). Model methods don’t always interact with a database but they usually do.

    As far as add/edit, they almost always share the same view and can share the same controller methods if doable.

    Just remember that the controller is the entry point for all your clients. Every URL your application handles should map to a controller method. The controller then tells the model what to do, passing the user input to it.

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

Sidebar

Related Questions

I'm trying to find out how to build nice and short alpha numeric hashes
I'm trying to build a nice looking config-screen using UITableView (much like the settings
I'm trying to build a page on my personal website that both used jQuery
I know this is a probable open ended question, and I have tried looking
I have spent most of my web-development career in the Microsoft camp, but for
We have a Linux box with Apache, running PHP. We have a regular Desktop
I'm trying to send out a Plain/HTML multipart email out and I'm currently using
I need to build a small monitoring scraper for a 3rd party website (it's
I've searching forever trying to figure out why IE will not save the current
Soon I will have to start a web project for a company, and I

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.