I have an idea for keeping code nice and clean
I create a class for each PHP-Page that has a template like this
( there's a lot more to this, but this is a rundown of the idea behind it )
filename is class.indexpage.php
<?php
class indexPage
{
public function getName() { return __class__; }
public function __construct();
{
$this->perform(); // this first for all pre-html-rendering functions
$this->render(); // this second to render the page
}
/*
public function load()
{
// this being the index page has the perform and render functions...
// ...being called from the __construct()
// if it was any other page, both functions would be called manually...
// ...by a load() function like this
// example:
$this->perform();
$this->render();
}
*/
private function perform()
{
// place all functions here that could effectively fail or break
// allowing the functions to fail or break before rendering the actual page
// so that the page doesn't fail somewhere in the middle of execution
}
private function render()
{
// place the html/PHP rendering side here
// only render the page here, so that you don't call mysql statements
// or general functions that fail in the middle of the script
// this way, you avoid the page stopping half-way because of errors
?>
<html>
<head>
<!-- Header stuff here -->
</head>
<body>
<!-- body stuff here -->
<body>
</html>
<?php
}
}
?>
i added the getName() function just for the purpose of being able to add all the
pages and classes to a single array (or class), allowing for them to be called from a variable
that can be passed through the scripts/functionCalls as a parameter.
filename is index.php
function __autoload( $class_name )
{
require_once( 'class.'.strtolower( $class_name ).'.php' );
}
new indexPage();
is this ok for keeping the failable/breakable functions away from the page render ?
and being able to Cleanly automate the process of adding new pages to the site.
...later an exception class of some kind will be created
this will be called as a function on any fail 🙂...
critic is appreciated 🙂
Regards,
Dev_M!nX