Lab 7

Lab 7

Project 2

Implementing best practices

Goal

  1. To improve your Project 2 to better prepare for Project 3
  2. To improve your PHP debugging skills by viewing the error_log file

Connecting to server

Remember that you must save your PHP files, upload them to the remote web server, open your file via an absolute URL, and do a "hard refresh" to test any changes.

Use WinSCP to connect to our remote server.

Details about your specific server, userid and password were emailed to you. Here is the general information:

  • Hostname: ftp.sienasellbacks.com   or   ftp.breimer.net
  • Username: userid@sienasellbacks.com   or   userid@breimer.net
  • Password: Sent via email
  • Port: 21
  • Use FTP; Do not use SFTP or SCM

Be sure to replace userid with your actual Siena userid; But, do not add @siena.edu

A. Understanding   make_page deeply and why we prepare content before calling it.

  1. Download sample_code.zip, unzip the folder and open make_list3.php
  2. Notice that the make_page function no longer assumes the content will come from a separate file. This assumption was convenient when our content was already in separate HTML files, but now consider that content will rarely come from files. It will either come from databases or it will be generated by PHP code.
  3. However, we can still use content from separate files, but we must get the content of the file first and pass it to the make_page function as string instead of passing the file name. This new approach allows us to get content from files, to generate content via loops, or to do both.
  4. To understand this deeply, combine the resume content and the automatically generated menu into a single string and then pass it to the make_page function.
  5. Concatenate the resume string to the content string and then pass the content string to the make_page function.

B. Creating and using a   make_columns function.

  1. Consider that we might want to display the resume and the program generated list side-by-side in a two column format. This is actually a very common task, so we should implement a function to do this. However, first try to do it manually. Rather than use your own CSS to create a two-column layout, use Bootstrap's Grid layout.
  2. Simply slice your content and resume strings into a Bootstrap grid structure with a row and two columns.
  3. Finally, consider that a website may only have a maximum of 3 columns.
  4. Write a function that takes 3 content strings and returns a single string that represents either a two or three column Bootstrap layout, depending on how many parameters are passed. An example will be shown in lab.

C. Understanding   make_list by fixing it and improving it.

  1. Open make_list4.php
  2. Upload it to the server and test it.
  3. Notice that the hyperlinks do not actually work.
  4. Try to identify the problem and fix it. There are two ways to fix it and we will discuss which way is better.
  5. Creating lists of hyperlinks is a very common task and it is often important to highlight the active or current link. This can be done in Bootstrap by adding the class name "active" to a list item, i.e, <li class="list-group-item active">
  6. Consider that we could pass another string ($a) to the make_list function to indicate which item to make active.
  7. Consider that we could slice in the word active into the class if the name of the list item matches the string $a
  8. Improve the make_list function by adding another parameter $a and an if statement that will add "active" to any list item whose name matches $a

D. Use what you learned to improve your Project 2 submission

  1. Simplify your own make_page function so that it accepts a single content string.
  2. Change your individual page generation PHP files, so that you "prepare" the string content by either getting it from files, generating it using code, or both.
  3. Implement and use at least one of the two functions we developed in lab.

DELIVERABLE

None. To get credit for lab you must work productively for the 2 hour period.

Do not share

While it is OK to help other students with concepts and general trouble-shooting, you should not share code. It is expected that each individual project will be unique.