Advanced PHP for Beginners

Page Class

Allows you to easily manipulate every aspect of an html page while it is being created.

Download Now!
Page ( [ $title ] )
doctype ( [ $type [, $standard ]] )
access ( $user [, $level ] )
eject ( [ $url [, $message ]] )
title ( [ $title ] )
description ( $description )
keywords ( $keywords )
robots ( $allow )
charset ( $charset )
link ( $external_file [, $combine ] )
body ( $insert_tag )
onload ( $javascript_function )
display ( $html )
An Advanced PHP for Beginners Example
The (X)HTML Output
Final Result
object Page ( [ string $title ] )top

Creates an (X)HTML page object.

$title:
You can set the page title here if you already know what it's going to be. The default is your website's name.
Example:
<?php

$page 
= new Page ('Page Title');

?>
doctype ( [ string $type= 'html' [, string $standard= 'strict' ]] )top

This solves probably the stickiest situation that programmers face. The wave of the future is XHTML, yet no browser supports it (correctly) and have no plans to either. It is a better way to program in my opinion, but I like my code to look the same in all browsers (read IE), and so I code in XHTML yet deliver my code in HTML through this class. It converts the XHTML to HTML (and vice versa to an extent) so that I have perfect markup that validates with no errors. The doctype can be declared sitewide using a global variable so there is no need ever to use this method, unless you have your reasons. If your code doesn't meet the strict standard, then it automatically delivers the page as transitional (or loose) if you have 'center', 'u', 'font', or 'iframe' (deprecated) tags, and to frameset if you use 'frames'. So when Internet Explorer goes the way of Netscape (I see no other way), your code can be switched to XHTML in a heartbeat. Just put an 'x' in your global.

$type:
Either 'html', or 'xhtml'. The default is 'html'.
$standard:
Either 'strict', 'transitional', or 'frameset'. The default is 'strict'.
Example:
<?php

$page
->doctype ('xhtml''transitional');

?>
access ( string $user [, integer $level= 1 ] )top

If you're particular about who views a certain page you can set permissions here.

$user:
Can be 'users', 'admin', or 'others'.
If 'users', only those who have signed in and have a $_SESSION['user_id'] can view this page.
If 'admin', only those who have $_SESSION['admin'] set can access the page.
If 'others', only those who have no $_SESSION['user_id'] can access the page.
$level:
This is for 'admin' access, and allows you to create unlimited levels of access based on the users $_SESSION['admin'] value. The default is 1.
Example:
<?php

$page
->access ('users');

?>
eject ( [ string $url [, string $message ]] )top

This is a handy method for forms especially. It sends the user somewhere else if needed.

$url:
Where the user is sent. Default='', ie. the BASE_URL.
$message:
What you would like to tell the user when they are ejected. Use "<br />" tags for newlines.
Example:
<?php

$page
->eject ('sorry.html'"It's nothing personal.")

?>
string title ( [ string $title ] )top

Sets or changes the page title.

$title:
What you want the page title to be. Leave blank if you just want the return value.
Returns:
The current page title.
Example:
<?php

$page
->title ('Advanced PHP for Beginners');

?>
description ( string $description )top

Sets the content for the meta description tag - default is the $page->title().

$description:
a string
Example:
<?php

$page
->description ('Jump start your programming.');

?>
keywords ( string $keywords )top

Sets the content for the meta keywords tag - default is the $page->title().

$keywords:
a string
Example:
<?php

$page
->keywords ('blazing speed easy to code ultimate reliability minimal knowledge');

?>
robots ( bool $allow )top

Tells the search engines if you would like them to crawl and index your page.

$allow:
Set to false if you don't want robots (crawlers) to index or follow this page. Default is true.
Example:
<?php

$page
->robots (false);

?>
charset ( string $charset )top

If for whatever reason you want to change this, you can do so here.

$charset:
Default is 'iso-8859-1'.
Example:
<?php

$page
->charset ('utf-8');

?>

The beauty of this method is that when you are dynamically creating content (the very purpose of PHP), and then realize you need something in the head section of your html, you can just put it there.

$external_file:
You can link to one file or many (in an array), and you can call this method as many times as you want. If there are any duplicates they will be taken out. To include anything else such as a google maps api you can include it here, you just need to spell everything out.

To include a.css, .js, or favicon.ico image in the head section of the page the:
.css files must reside in the directory '/base/directory/yourwebsite.com/include/head/css/', and cannot have a '-' in the filename
.js files must reside in the directory '/base/directory/yourwebsite.com/include/head/javascript/', and cannot have a '-' in the filename
.ico image must reside in the directory '/base/directory/yourwebsite.com/include/head/'

The reason you can't have dashes in the filenames is because all of your javascript and css files are combined, minimized, and compressed with a little .htaccess magic and the filenames in the url are separated by dashes. All of this fancy footwork causes your page to load with blazing speed, and makes your users very happy.
$combine:
If you would like your web pages to take forever to load while the browser requests every external bloated file on your server individually like most web pages do, then you can set this to false. Otherwise the default is true, and all of your .css and .js files will be combined, compressed, and served in a single file.
Example:
<?php

$page
->link ('style.css');
$page->link (array('layout.css''style.css''fancy.js''favicon.ico')); // the duplicate style.css will be thrown out
$page->link ('<script type="text/javascript" src="http://maps.google.com/maps?file=api&v=2&key=' $key '"></script>');

?>
body ( string $insert_tag )top

Sometimes you just need to put something in the body tag. Well, here you go.

$insert_tag:
a string
Example:
<?php

$page
->body ('onload="googleMaps()" onunload="GUnload()"');

?>
onload ( string or array $javascript_function )top

This is to call multiple javascript functions after the page loads. Use as you would $page->link(). The only limitation is that you can't pass any variables with the functions, you can only submit the function name.

$javascript_function:
A string or an array of javascript functions to call after the page loads.
Example:
<?php

$page
->onload (array('javaScriptFunction''startLoadingMoreImages'));
$page->onload ('throwUpPopUnders("Netflix", "casalemedia")'); // WRONG!! No parameters, remember?  It was an annoying idea anyways.

?>
string display ( string $html )top

Returns the entire page, so this is the last function of all that you will call.

$html:
The entire content of your page between the body tags. If you echo or print anything before this method call, it will screw up the whole (x)html layout. So instead of echo or print, just keep adding everything to the $html variable then echo $page->display ($html); and there you have it - fast, efficient, beautiful code.
Returns:
All of your (X)HTML code, packaged and ready to ship.
Example:
<?php

echo $page->display ($html);

?>
An Advanced PHP for Beginners Example:top
<?php

$page 
= new Page;

$html 'Hello World!';

echo 
$page->display ($html);

?>
The (X)HTML Output:top
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
  <title>Advanced PHP for Beginners</title>
  <meta name="description" content="Advanced PHP for Beginners">
  <meta name="keywords" content="Advanced PHP for Beginners">
  <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
</head>
<body>
  Hello World!
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        </body>
</html>
Final Result:top
Bookmark This Page
Home
Download
Contact Us