Category Archives: PHP

PHP – Adding Functions to Your Template

This demonstration series will show you how you can create and include a ‘functions.php’ external file to your Project1 template.

Specifically, you will learn how to create and implement a script as a user-defined function that dynamically names the following on all the pages:

  • <title></title>
  • the banner area’s <h2></h2>
  • a class/ID name to be used wherever you wish
  • <img> source file and its alt text

You will see how to implement it by declaring the function in an external ‘functions.php’ file, including the ‘functions.php’ file inside the ‘head.inc.php’ file, and also calling the function inside the ‘head.inc.php’ file so that you can use its global scope variables anywhere within the template’s component pages.

Lastly, the demo also explains the difference between echoing the function’s results vs. using the stored variable values generated by a function from an external include() page.

Continue reading PHP – Adding Functions to Your Template

JS – Project1 – Mobile JS Menu (+ more)

This demo series will show you how you can make your navigation mobile friendly and accessible using jQuery whether javascript is enabled on the client-side or not.

JS Mobile Menu Demo Series

This series is approximately 45 minutes long. You should expect it to take at least twice that time to do complete the work.

1 – Menu setup (18min)
2 – jQuery setup and custom script (17min)
3 – Styling the menu for proper behavior (13min)

 

 

Continue reading JS – Project1 – Mobile JS Menu (+ more)

CSS – Creating a Mobile-First Design Template

Creating a Mobile-First Design Template for Your PHP Project

This demo will give you guidance in styling a web page with HTML5 markup from a mobile-first design approach. It covers the following concepts, principles, and methods:

  • the php/html starter file’s proper markup
  • how to add Google Fonts to a design
  • using a viewport/device-width meta tag
  • removing native browser styling with a ‘reset’ css file
  • using @viewport and @-ms-viewport in CSS
  • designing for smallest screens in mind first
  • using @media queries to alter layout on larger screens
  • styling a baseline for very commonly used elements

To follow along with these videos using the exact same markup,  download the template ‘project1’ folder in a zipped file. After downloading, unzip and place the unzipped folder into your “htdocs/” folder to work on the files.

Creating a Mobile-First Responsive Site Template
(7-Part Video Demo Playlist BELOW)

Approximately 2.5 hours of demo. Expect the work you do to create your own base design template to take a minimum of 8 hours.

00 – Getting Started (19:37)
01 – Start Styling (27:49)
02 – Styling the Banner (24:46)
03 – Styling the Banner’s NAV (22:25)
04 – Styling the Baseline Content (20:53)
05 – Styling the Baseline Content (Continued 14:26)
06 – Styling the Footer / Using Additional Breakpoints (22:51)


 


Want to learn more about using Google Web Fonts?

Check this video out.

 

Useful Project Resources

XAMPP – TURN YOUR MAC INTO A DEVELOPMENT SERVER

Installing XAMPP on your MAC personal computer

XAMPP stands for “X (one of four OSs), Apache, MySQL, PHP, PERL” and is used to enable your personal computer with the web and database tools necessary to host its own dynamically driven websites for testing and development purposes. The following tutorial video demonstrations will show you the steps to set your computer up as a “localhost” server on a Mac. Continue reading XAMPP – TURN YOUR MAC INTO A DEVELOPMENT SERVER

PHP – Lesson 10 : Functions

Functions Overview

What is a function?

  • A function is a way to write modularized code that can be used more than once just by calling out its function name in a script.

Where do I find functions?

  • Functions are largely what PHP is built on. PHP has over 3000 built-in functions you can use so you don’t have to reinvent the wheel every time you want to do a set of tasks.
  • You can also create your own custom funtions to perform custom tasks.

What are advantages of using functions?

  • For tasks you need to repeat in several places in the code, you can simple call out a funtion from a centralized place instead of writing the same coded over and over.
  • When updating the code, you can update a single function in one place rather than modifying code in several places.
  • They usually speed up the processing time of your pages.


How do I make my own function?

Let’s say you want to create a function that automatically adds the sales tax into a subtotal to give you a final price. We will call it “Total” and the tax will be 7.75%, as follows:

  • function Tax($subtotal) {
    return $subtotal *= .0775;
    }

What this will do is take any value called by the “Tax” function and substitute that passed value in place of “$subtotal.” For instance, if we are explicit and want to find the tax on twenty dollars, we could invoke the function as follows:

  • $tax = Tax(20);
    echo "\$$tax";

This would result in outputting the string (no quotes) of ” $1.55 “. You could produce the same results by running the function on a variable instead of a raw number:

  • $amount = 20;
    $tax = Tax($amount);
    echo "\$$tax";

Variable Scope And Functions

It is important to note that functions are self-contained. What happens with variables inside of a function is invisible to the rest of the script outside of the function. When variables are passed as arguments to a function, only the value is passed; thus, once the function completes its task, the variables inside of it cease to exist, and they are only created or invoked again if the function is reused.

“The scope of a variable – in other words, where it can be used – depends entirely on where the variable is defined. A variable defined in a function or as one of its parameters is limited in scope to that function. It cannot be seen outside the function. Equally, a function has no knowledge of or influence over variables outside.”

(from Adobe Dreamweaver CS5 with PHP by David Powers)


Demo : Create a User-Defined Gallery Function

To learn how you can create a user-defined gallery function, go to the “Creating a Gallery Function” demo page. It will show you how you can write a customizable gallery function that scans gallery directories to populate thumbnail galleries with larger lightbox effect opening images. No database necessary. . . . Additionally, it covers the concepts important to reusable code (i.e. functions).

XAMPP – Turn your PC into a development server

Installing XAMPP on your personal computer

XAMPP stands for “X (one of four OSs), Apache, MySQL, PHP, PERL” and is used to enable your personal computer with the web and database tools necessary to host its own dynamically driven websites for testing and development purposes. The following tutorial video demonstrations will show you the steps to set your computer up as a “localhost” server on Windows. Continue reading XAMPP – Turn your PC into a development server

MAMP – Turn your Mac into a development server

Installing MAMP on your personal computer

MAMP stands for “Mac Apache, MySQL, PHP” and is used to enable your personal computer with the web and database tools necessary to host its own dynamically driven websites for testing and development purposes. The following tutorial video demonstrations will show you the steps to set your computer up as a “localhost” server. Continue reading MAMP – Turn your Mac into a development server

PHP – Lesson 11: Using COOKIE and SESSION

This lesson demonstrates how the PHP  $_COOKIE and $_SESSION superglobal arrays work. On this page are three slideshow/demo videos, as follows:

  • Slideshow lesson on how we use $_COOKIE and $_SESSION to get info from users
  • Demonstration on how to build simple, basic code to illustrate $_COOKIE
  • Demonstration on how to build simple, basic code to illustrate $_SESSION

Continue reading PHP – Lesson 11: Using COOKIE and SESSION