php includes for modularization cit 230 – web front-end development

12
PHP INCLUDES FOR MODULARIZATION CIT 230 – WEB FRONT-END DEVELOPMENT

Upload: sherilyn-park

Post on 16-Jan-2016

221 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: PHP INCLUDES FOR MODULARIZATION CIT 230 – WEB FRONT-END DEVELOPMENT

PHP INCLUDESFOR MODULARIZATIONCIT 230 – WEB FRONT-END DEVELOPMENT

Page 2: PHP INCLUDES FOR MODULARIZATION CIT 230 – WEB FRONT-END DEVELOPMENT

WHAT IS MODULARIZATION?

• Modularization is the idea of

separating a website into modules.

• A module can be a section that

repeats itself across a website.

• Example: Website headers and

website footers can be modules.

They are usually the same

throughout an entire website.

Website Body

Header

Footer

Page 3: PHP INCLUDES FOR MODULARIZATION CIT 230 – WEB FRONT-END DEVELOPMENT

WHY USE MODULARIZATION?

• Imagine a 250-page website that needs an update in the footer.

• With html only, you’d have to edit every single page, which would be a

very tedious and error-prone task (even with copy/paste).

• It saves time, money, and is easy to maintain.

• It can be done with a PHP include.

Page 4: PHP INCLUDES FOR MODULARIZATION CIT 230 – WEB FRONT-END DEVELOPMENT

WHAT IS A PHP INCLUDE?

• PHP is a scripting language used for web development.

• include is a command in the PHP language.

• It tells PHP to “include” a file.

• This is how a website can be modularized.

Page 5: PHP INCLUDES FOR MODULARIZATION CIT 230 – WEB FRONT-END DEVELOPMENT

SYNTAX OF PHP INCLUDE STATEMENT

• The syntax is composed of 5 elements

1. The opening PHP tag: <?php

2. The include command itself: include

3. The file path and name in quotes: ’/modules/footer.php’

4. A semi-colon to end the PHP statement: ;

5. The closing PHP tag: ?>

• The result: <?php include ’/modules/footer.php’; ?>

Page 6: PHP INCLUDES FOR MODULARIZATION CIT 230 – WEB FRONT-END DEVELOPMENT

WHERE TO INCLUDE THIS PHP INCLUDE?

• The include statement can go right in the html code.

• This is part of the file path. It tells the server to start at the root.

• Without this segment, the path would look something like this instead:

Page 7: PHP INCLUDES FOR MODULARIZATION CIT 230 – WEB FRONT-END DEVELOPMENT

FILE STRUCTURE

• With PHP include, you only need

1 file per module.

• A suggestion is to keep them

organized into a module folder.

• Example: footer.php can be

designated to be the only footer

file across the entire website.

Page 8: PHP INCLUDES FOR MODULARIZATION CIT 230 – WEB FRONT-END DEVELOPMENT

WHAT IS INSIDE THE MODULE FILE?

• The actual code that will be inserted!

• It is not an html file, so <!DOCTYPE>,

<html>, etc. are not needed.

• Think of it as a snippet of code that is

going to be inserted into a real html

file (the one with the php include).

Page 9: PHP INCLUDES FOR MODULARIZATION CIT 230 – WEB FRONT-END DEVELOPMENT

EXAMPLE: BEFORE PHP INCLUDE

Page 10: PHP INCLUDES FOR MODULARIZATION CIT 230 – WEB FRONT-END DEVELOPMENT

EXAMPLE: AFTER PHP INCLUDE

Page 11: PHP INCLUDES FOR MODULARIZATION CIT 230 – WEB FRONT-END DEVELOPMENT

WHAT ABOUT THE PAGE SOURCE?

• Assuming the web host

supports PHP, visitors will

not see the php code in

the page source.

PHP leaves no evidence!

Page 12: PHP INCLUDES FOR MODULARIZATION CIT 230 – WEB FRONT-END DEVELOPMENT

RESOURCES

• From PHP itself:

http://php.net/manual/en/function.include.php

• YouTube video on using PHP includes to modularize a website:

https://www.youtube.com/watch?v=R7k1K7UMs50

THANK YOU