Jump to content

OOP - Choosing a method to load in an MVC


liam1412

Recommended Posts

Hi There

 

I am reasonably new to OOP and am trying to build a very basic MVC for use in my own work; the ones available are just way to bloated for the sites I build. 

 

I have got my function to load a controller working, but how do I get it to load the method I want, or if no selected method exists autoload the index() method.

 

Here is my current loadController();

 

  function loadController($controller,$default_controller)
  {
  
    if(!empty($controller))
    {
      $controllerpath = 'controllers/'.$controller.'Controller.php';
      
      if(file_exists($controllerpath))
      {
      
      include $controllerpath;
      
      } else {

        header("location:views/errors/404.html");
        exit();
        
      }
      
    } else {
    
      include 'controllers/'.$default_controller.'Controller.php';
    
    }
    
  }

 

Thanks for your help

Link to comment
https://forums.phpfreaks.com/topic/173198-oop-choosing-a-method-to-load-in-an-mvc/
Share on other sites

The dispatching process is being performed by the FrontController pattern internally it will use a router of some kind to map a request to a physical location (a file on your hard drive).

 

So if you would get a request like:

/users/me

 

It could translate to:

UsersController::meAction()

 

The translation would be made possible by your router and a few function calls that translate users to UsersController (same for me). Afterwards a dispatcher will use UsersController and meAction and will try to execute it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.