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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:02:38+00:00 2026-06-04T06:02:38+00:00

I am currently working on a mini ‘framework’ and I am having some difficulties.

  • 0

I am currently working on a mini ‘framework’ and I am having some difficulties. I’m attempting this in order to strengthen my understanding of basic concepts utilized in most MVC’s (At least from what I have seen). So yes, I do understand that using a framework may be easier and not everything that I am doing is ideal. I am just trying to learn more.

So I have 2 files that I am currently working with.

FrontController.php

<?php   
class FrontController {
    public function __construct() {
        $this->go(); // RUNS GO FUNCTION UPON LOADING
    }

    public function go() {          
        $url = $_SERVER['REQUEST_URI']; // GRABS URL
        $action = explode("/", $url); // SPLITS UP URL INTO SECTIONS

        $object = ucfirst($action[2]) . "Controller"; // SETS 2ND SECTION OF URL TO UPPERCASE AND IDENTIFIES THE CONTROLLER
        $file = APP_DIR . "/" . $object . ".php"; // IDENTIFIES THE FILE THAT WILL BE USED

        if(!is_file($file)){ // DETERMINES IF FILE EXISTS
            $this->fail(); // IF NOT, FAILS
        } else {
            require_once $file; // IF EXISTS, PULLS IT IN
            $method = ucfirst($action[3]); // THE 3RD SECTION OF THE URL IS THE METHOD
            $controller = new $object(); // CREATE INSTANCE OF THE IDENTIFIED OBJECT

            if(!method_exists($controller, $method)){ // DETERMINES IF METHOD EXISTS IN THE CLASS
                $this->fail(); // IF NOT, FAILS
            }

            $controller->$method(); // RUN METHOD
            exit(0);
        }
    }

    public function fail() {
        echo "<h1>Failure</h1>"; // FAILURE MESSAGE
    }
}

/application/BaseController.php

<?php   
class BaseController {
    public function __construct() {
        $this->session();
    }

    public function session() {
        session_start();
        $_SESSION['is_logged_in'] = 1;
        echo "hi";
    }
}

So what I would like to be able to do is extend the BaseController with the FrontController. I figured that extending the BaseController would allow me to add common functionality to my entire application. The problem is that I am not certain how to do this properly. I know that I need to ‘require’ BaseController.php into FrontController.php somehow, but I have seen many different ways and I want to know which is most correct.

What I have tried is simply adding ‘require_once(“/application/BaseController.php”);’ to the top of FrontController.php and then extending the FrontController class, but this isn’t working (blank page), and from what I have read, it is not the best way.

I read into __autoload() but I do not understand how to use it effectively. Do I just put this at the top of my FrontController.php file and extend my class after that?

So, to summarize, I would like to extend my FrontController class (and other future classes, when necessary) with my BaseController. I would just like some advice for how to accomplish this task effectively. It may even be possible that the way I have this thought out is ass backwards, and if that is the case, please let me know!!

  • 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-04T06:02:39+00:00Added an answer on June 4, 2026 at 6:02 am

    You extend classes like:

    <?php
    class FrontController extends BaseController {
     ..code...
    }
    
    
    ?>
    

    __autoload is a magic method which loads classes automatically. So you could add this in your FrontController as an example and load your controllers as needed. Read about autoloading classes here:

    http://php.net/manual/en/language.oop5.autoload.php

    Also, take advantage of SPL in PHP which will help define your application better.

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

Sidebar

Related Questions

Im currently working on a Python/Pygame module to wrap some basic sprite animation. Animation
Currently working on a VBScript to automate some of the dirty PST ingestion work
Currently working on a flex AIR project based on PureMVC framework. There was a
I'm currently working on learning some game development with Java. I'm working on the
I'm currently working on a game engine in java, however I'm having preformance issues
Im currently working on making a flash platformer engine...but my collision detect needs some
Im currently working on a c# project that uses another .net library. This library
Im currently working on creating some appwidgets for my application; one of those is
Currently working on something which uses ajax for some pagination. What I'm looking to
Currently working on a nice three step order form for a wedding photographer, so

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.