johnsmith153 Posted December 1, 2010 Share Posted December 1, 2010 I am putting together a basic OOP application. There is one access page - index.php. This is the kind of thing my index.php page does: <?php //get address bar / POST / GET info $request = new Request(); //if POST request submitted then the code is executed here before redirecting back to the page (stores POST vars in SESSION) if($_POST) { $post = new Post(); } //checks device using (mobile etc.) and decides if any action needed (really old mobiles are sent straight to a mobile site) + stores details of the device using $device = new Device(); //main controller to decide files to load for header, page-controller and view $mainController = new MainController();//__construct gets the files //check login / autologin $login = new Login();//checks if should log in automatically (page controller below will throw off when MUST be logged in as not always) //execute the page controller $mainController->pageController(); //header $mainController>header(); //view $mainController->view(); ?> Is ts the way to go about it? Is listing class executions down the page like this the right way or should say the main controller execute a lot of these? Please don't post your index.php page, I am looking how I can adjust mine - unless mine is utter rubbish of course! I don't want to learn one of the ready-made frameworks just yet - but will do soon. Thaks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/220366-oop-does-this-seem-right/ Share on other sites More sharing options...
trq Posted December 1, 2010 Share Posted December 1, 2010 It's one way of doing things I guess, I definitely wouldn't do it that way though. You should take a look at the MVC pattern. Implementing that your index.php file would simply be in charge of bootstrapping then handing over execution to the front controller or application object. Quote Link to comment https://forums.phpfreaks.com/topic/220366-oop-does-this-seem-right/#findComment-1141877 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.