scottybwoy Posted March 1, 2007 Share Posted March 1, 2007 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. Quote Link to comment Share on other sites More sharing options...
scottybwoy Posted March 1, 2007 Author Share Posted March 1, 2007 Does this make sense at all or is it a bit long? Quote Link to comment Share on other sites More sharing options...
monk.e.boy Posted March 1, 2007 Share Posted March 1, 2007 Does this make sense at all or is it a bit long? No. Yes. monk.e.boy Quote Link to comment Share on other sites More sharing options...
scottybwoy Posted March 2, 2007 Author Share Posted March 2, 2007 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.