liam1412 Posted September 5, 2009 Share Posted September 5, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/173198-oop-choosing-a-method-to-load-in-an-mvc/ Share on other sites More sharing options...
ignace Posted September 5, 2009 Share Posted September 5, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/173198-oop-choosing-a-method-to-load-in-an-mvc/#findComment-913126 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.