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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.