Here's my original page without full code separation:
<?php
session_start();
include_once("appleFunctions.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtmli/DTD/xhtmli-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Apple Learning</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link href="headerCss.css" rel="stylesheet" type="text/css" />
<link href="forgotPageCss.css" rel="stylesheet" type="text/css" />
<link rel="icon" type="image/png" href="favicon.png" />
</head>
<body>
<div id="header">
<div id="sitebranding">
<h1>AppleLearning</h1>
</div>
</body>
</html>
And here's what my new page with code separation is looking like so far:
header.tpl.html:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtmli/DTD/xhtmli-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>TITLE</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <link href="headerCss.css" rel="stylesheet" type="text/css" /> <link href="forgotPageCss.css" rel="stylesheet" type="text/css" /> <link rel="icon" type="image/png" href="favicon.png" /> </head> <body> <div id="header"> <div id="sitebranding"> <h1>AppleLearning</h1> </div> </body> </html>
My problem is I don't understand how to get the top php stuff into my page"
<?php
session_start();
include_once("appleFunctions.php");
?>
I have a createPage function:
function createPage($templateName='index.tpl', $title='My Site', $params=array())
{
// Load the template providided via the function parameter.
$pageText = file_get_contents($templateName . '.html');
// Replace each of the optional $params key=>value pairs in
// the page text.
foreach ($params as $_key => $_value) {
$pageText = str_replace($_key, $_value, $pageText);
}
// And finally replace the title, and return the now
// filled out template page.
return str_replace('TITLE', $title, $pageText);
}
And an index page:
<?php
/** index.php */
include_once("appleFunctions.php");
$headerData = array();
$headerPage = createPage('header.tpl.html', 'Header - My Site', $headerData);
?>
How am I to get this stuff into the header.tpl.html page?:
<?php
session_start();
include_once("appleFunctions.php");
?>
Also, once I do that how do I actually display the page? Do I have to just echo something?
Sorry, this is all a little confusing to me right now but I think this is for the best for sure.
EDIT: Now that I look it over I don't really need to include the functions page because it's already included in index.php, correct?
Though I do need to do the start_session() call.
This is what I tried:
$headerData = array('START_SESSION' => 'session_start();');
$header = createPage('header.tpl', 'AppleLearning', $headerData);
echo $header;
With this in my template:
START_SESSION <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
That doesn't work though. When I load the page, there's just text, session_start(); on the screen.
EDIT: Still nothing working, but this is what I've done:
<?php
/** index.php */
include_once("appleFunctions.php");
// No values provided, just using defaults.
//$index = createPage();
// An "About page" using the default title.
//$about = createPage('about.tpl');
// A user profile page, using a username and and
// a user ID.
$headerData = array('START_SESSION' => '<?php session_start(); ?>');
$header = createPage('header.tpl', 'AppleLearning', $headerData);
//echo $header;
// The login/signup page
$loginData = array('INCLUDE_HEADER' => '<?php echo $header; ?>', 'INCLUDE_SIGNIN' => '<?php include("appleSignIn.php"); ?>',
'INCLUDE_LOGIN' => '<?php include("appleLogin.php"); ?>');
$login = createPage('loginLayout.tpl', 'AppleLearning', $loginData);
echo $login;
?>
header.tpl.html:
START_SESSION <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtmli/DTD/xhtmli-strict.dtd"> <!-- Started 5/22/2011 2:05PM EST --> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>TITLE</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <link href="headerCss.css" rel="stylesheet" type="text/css" /> <link href="forgotPageCss.css" rel="stylesheet" type="text/css" /> <link rel="icon" type="image/png" href="favicon.png" /> </head> <body> <div id="header"> <div id="sitebranding"> <h1>AppleLearning</h1> </div> </body> </html>
Some of loginLayout.tpl.html:
INCLUDE_HEADER INCLUDE_SIGNIN INCLUDE_LOGIN <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtmli/DTD/xhtmli-strict.dtd"> <!-- Started 5/22/2011 2:05PM EST --> <!-- Login/SignUp Page --> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <link href="indexCss.css" rel="stylesheet" type="text/css" /> </head> <body>
In the index page I'm not sure if this is working, though probably not:
$headerData = array('START_SESSION' => '<?php session_start(); ?>');
And I know this is not working:
$loginData = array('INCLUDE_HEADER' => '<?php echo $header; ?>', 'INCLUDE_SIGNIN' => '<?php include("appleSignIn.php"); ?>',
'INCLUDE_LOGIN' => '<?php include("appleLogin.php"); ?>');
$login = createPage('loginLayout.tpl', 'AppleLearning', $loginData);
echo $login;
That's definitely not working because there's no way my createPage function knows what $header is anyway, plus I checked and the signin and login scripts are definitely not being included in the page.
I guess my big question is how do you do things other than layout in this code separation method? Like how do you do includes, session starts, how would I even call a function if I needed to? I'm looking through content on DIC but everything is just basic layout stuff and printing words on the screen, not doing PHP functions and what not.
This post has been edited by eZACKe: 06 June 2011 - 04:04 PM

New Topic/Question
Reply




MultiQuote





|