Jump to content

Presenting Templates


scottybwoy

Recommended Posts

Hey peeps,

 

I've been working with my templates and scripts for a while now, and have decided that the way they are being used is very messy.  I have a home class, that checks the login then looks for page requests by the user and then displays whatever is returned.  This is what I had before (that worked) :

<?php
$content = $_REQUEST['content'];
$company = $_REQUEST['company'];
$modelId = $_REQUEST['modelId'];

if (!empty($content)) {
    	$constant = $content . ".php";
$template = SCRIPTS . "/$constant";
} elseif (!empty($company)) {
    	require(COMPANY_SCR);
} elseif (!empty($modelId)) {
    	require(PRODUCT_SCR);
} elseif ($content == "") {
    	$template = ADMIN_SCR;
}

echo "<div id='container'>";
require_once(HEADER);
echo "<div id='content'>";		
require($template);
echo "</div>";
include(TEMPLATE_DIR . "/inform.php");
include(TEMPLATE_DIR . "/prodDisp.php");
include(TEMPLATE_DIR . '/footer.php');
echo "</div>";

?>

Now my Scripts called by $content use include / require to display the relevant template however COMPANY_SCR / PRODUCT_SCR use return $template; at the end of their functions.

 

Each Class Script is initiated by a call to a loading function for instance :

<?php
$thisApp = new custApp();

$thisApp->custCheck();
?>

All classes extend Home Class and an initial called function may look like this :

<?php
function custCheck() {
// The if statement this gets the select values
// Then it checks how this page was called and what data is available

if (isset($_REQUEST['company'])) {
	$this->custLoad($_REQUEST['company']);
} else {
	require(CUST_PAGE);
}

}
?>

The custLoad function returns $template as an object which in turn goes back to the Home Class calling function and loads the required template, this makes sense and is how I want it to work.  However the scripts that are called via $content must use require / include to work and is starting to become a labyrinth of includes due to my lack of understanding, from what I have worked out it is probably down to the way variable functions behave, but I have not been able to work out an alternative.

 

I tried using a switch case, but this created unexpected results.

<?php
switch ($content) {
    	case 'customer':
    		require(COMPANY_SCR);
    		break;
    	case 'client':
    		require(CLIENT_SCR);
    		break;
    	case 'product':
    		require(PRODUCT_SCR);
    		break;
    	case 'sale':
    		require(SALE_SCR);
    		break;    		
    	default:
    		require(ADMIN_SCR);
    		break;
}
?>

Any pointers / suggestions would be greatly received.

Link to comment
Share on other sites

Ok The simple question would be, does anyone have a good technique for presenting templates, under a class framework, where one parent class (namely home) uses other daughter scripts to process the information before learning which template is to be presented and using return to pass back $template to the home class.

 

Thanks for your time.

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.