Page 1 of 1

problems with OOP template

Posted: Wed Nov 26, 2003 4:18 pm
by mx2kstudio
Well First off, I've found most of my solutions in forums or just by messing around with the code for a while. However I am far from being any kind of programmer and stay on more to the design side of things.

because the of the "CreatePage()" function defined in seperate class which does the creation of the actual page and anything else that is sent via "echo" or "print" comes up before the created page.
the "return" feature (for lack of a better word because i know its not a function) only returns one variable, then stops. unless you build a return array. With this OOP templates / php scripts that create the individual pages, I understand that you can not use "echo" or "print" or "printf", otherwise it sends this straight to the page before anything else.

Well here is my problem, I only know how to query MySQL and "printf" or "echo" a table with the desired information. However if you do this with the php script, it will send out the table of information before the page is created. But I need the information sent out when the page is created so that it shows up in the correct spot. And return will not allow for me to create more than one row. So how do I go about creating a quiery that allows me the flexibilty of printing all the rows that I need but is created with the page and not before??



this is about far as I can get, if anyone can help or at least point me to the right direction about where I can more explicit documentation than php.net in how to handle something like this, that would be awesome.


here is what i have so far

Code: Select all

<?php # index

// This is the index page which uses the HtmlTemplate2 class.

session_start();
require_once ("class/HtmlTemplate.class"); // Include the class.


$page = new HtmlTemplate2 ("templates/v3index_template.inc"); // Create an instance.

$page->SetParameter("PAGE_TITLE", "GetEpic Version 3.0"); 

$javascriptmenu = implode("\n", (file("includes/v3menu.inc")) );
$page->SetParameter("JAVASCRIPT_MENU", $javascriptmenu);

$loadmenu = implode("\n", (file("includes/insertmenu.inc")) );
$page->SetParameter("LOAD_MENU", $loadmenu);

// Greet them if they are logged in or show the login form.
if ($HTTP_SESSION_VARS[first_name]) {
$login= "Greetings, $HTTP_SESSION_VARS[first_name]!";
} else {
$login = '<div align="right"><form action="login.php" method="post"> 
<pre>



Username: <input size="15" class="field" type="text" name="username" id="username"> Password: <input size="15" class="field" type="password" name="password" id="password"> <button width="8" height="8" class="nom" type="submit" name="Submit">GO</button> </pre>
</form></div>';
}
$page->SetParameter("PAGE_LOGIN", $login);

if ($error_message) {
$content = $page->CreateErrorMessages($error_message);
} elseif ($good_message) {
$content = '<div align="left"><font color="blue"><b>' . urldecode ($good_message) . '</b></font></div><br></br>'; 

}


function get_bdates() {

require_once("includes/config_v3_db.inc");

$result = mysql_query("SELECT * FROM birthday WHERE timedate > NOW() ORDER BY timedate ASC LIMIT 5",$db)
or die("unable to select table");

if ($myrow = mysql_fetch_array($result)) {

do {


$bar = printf("<tr><td class='date'>%s</td><td width='168' class='linetext'>%s</tr>\n", $myrow["date"], $myrow["birthday"]);
return $bar;




} while ($myrow = mysql_fetch_array($result));



} else {

return "Sorry, no records were found!";

}
}



$bdates = $bar;
$page->SetParameter("DATE_BIRTHDAYS", $bdates); 

$band = implode("\n",(file("includes/band.inc")) );
$page->SetParameter("PAGE_BAND", $band);

$venue = implode("\n",(file("includes/virginia_venue.inc")) );
$page->SetParameter("PAGE_VENUE", $venue);

$footer = implode("\n",(file("includes/footer.inc")) );
$page->SetParameter("PAGE_FOOTER", $footer);



$page->CreatePage(); // Send the page to the browser.
unset ($page);

?>

Posted: Wed Nov 26, 2003 10:01 pm
by McGruff
It takes a little while to get a grip on OOP.

These are useful links:

ftp://ftp.cs.orst.edu/pub/budd/oopintro ... /info.html
phppatterns.com

After a very quick look at the script you posted, it looks like any vars output on the page have to be set with the setParameter method - so use that rather than echo'ing.

Echo'ing vars direct from scripts is bad practice anyway: better to keep the presentation side of things separate by defining a bunch of vars first and then printing them later in templates - which seems to be what the class wants you to do.

Did you write the class yourself? If not there might be a user manual in which to look for help.