Hi there,
I have been building a site in my standard way, each page doing its own thing via functions on that page. I have been asked to convert this into OO and am having somtrouble understanding what goes where!
The first class I have made is a layout class that constructs the html page template. Take the login page, the pagelayout.inc (containing the Page class) contains the Display function:
function Display()
{
$this -> DisplayHeader();
$this -> OpenMainTable();
$this -> OpenMenuTable();
$this -> DisplayLogo();
$this -> DisplayMenu();
$this -> DisplayQuickLogin();
$this -> CloseMenuTable();
$this -> OpenContentTable();
echo $this -> content;
$this -> CloseContentTable();
$this -> CloseMainTable();
$this -> DisplayFooter();
}
login.php simply looks like:
<?php
$content //tables etc
require('pagelayout.inc');
$homepage = new Page();
$homepage -> SetContent($content);
$homepage -> Display();
?>
The page renders ok, and in the case of login.php, the $content displays a table for users to insert username and password.
What I cant get my head round is what i do next. The login needs to use the php function "authenticate" to do the database query to see if a user exists.
The function runs the db query, then based on the result should forward the user to page, or return some kind of feedback - likewise for a failed login.
In terms of good OO design, should this authenticate function be kept in a separate external class file and called by the Submit action? or is it considered ok practise to simply include the authenticate function on the login.php page?
If it is the former, and I need an authenticate class, i cant find any example of how I could implement this.
I might have completely the wrong end of the stick - any help you can offer either way would be very much appreciated. I have tried a couple of books, but there examples dont go beyond implementing one class, and certainly not one that contains dynamic content.
Regards,
James