Jump to content

OOP - Does this seem right?


johnsmith153

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/220366-oop-does-this-seem-right/
Share on other sites

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.

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.