You are on page 1of 11

Day 1

Preparation of laptops
● Install git
● Install PhpStorm and activate license
● Install PHP
● Install Slack
● Configure account for the courses:
○ SensioLabs connect
○ Activate them on SensioUniversity
○ Create account on SymfonyCasts
○ Create Udemy account

Courses: The basics

Linux basics
● We make sure everyone has access to the linux terminal locally
● Course: https://www.udemy.com/course/linux-terminal-for-beginners/

Git basics

1. We start with installing git locally


2. Create a Gitlab account
3. Course: https://www.udemy.com/course/introduction-to-git-for-gitlab-projects/
Day 2

PHP basics
- https://symfonycasts.com/screencast/php-ep1 How to win friends & develop in PHP
- https://symfonycasts.com/screencast/php-ep2 Course 2: How to stop worrying & start
writing PHP
- Please read Chapter 4 (only chapter 4
https://phptherightway.com/#language_highlights)

Done? Start on the assignment for the remainder of the day.


Day 3 and 4

Courses: Database
- https://symfonycasts.com/screencast/php-ep3 Talking to a MySQL Database in PHP

We’ll assist you in setting up MariaDB.

Done? Continue on the assignment for the remainder of the day.

Day 5

Courses: Object Oriented programming part 1


- https://symfonycasts.com/screencast/oo
- https://symfonycasts.com/screencast/oo-ep2

Day 6

Courses: Object Oriented programming part 2


- https://symfonycasts.com/screencast/oo-ep3/extends
- https://symfonycasts.com/screencast/oo-ep4/class-constants

Day 7

Courses: Namespaces and error handling


- https://symfonycasts.com/screencast/php-namespaces/namespaces
- https://www.youtube.com/watch?v=XQ5Pd-6Hnjk

Reading material:
- https://phptherightway.com/#errors_and_exceptions (only error and exception
chapter)
- http://bestpractices.thecodingmachine.com/php/error_handling.html
- https://netgen.io/blog/modern-error-handling-in-php

Done? Continue on the assignment for the remainder of the day.


Day 8

Courses: Design patterns


- https://symfonycasts.com/screencast/solid/solid

Reading material
- Read chapter 6 https://phptherightway.com/#coding_practices
- It also contains a link to https://designpatternsphp.readthedocs.io/. Make sure you
read that.
- Read chapter 7 https://phptherightway.com/#dependency_injection

Done? Continue on the assignment for the remainder of the day.

Day 9

Courses: Composer
- https://symfonycasts.com/screencast/composer/composer

Reading material
- Read chapter 5 https://phptherightway.com/#dependency_management

Done? Continue on the assignment for the remainder of the day.


Assignment 1 - Applying the basics
This assignment has to be done individually.

For this you need to create an empty git repository. We will provide you a Gitlab repository to
push to. Try to create small commits per working change.

It’s okay to search on the Internet and Stack Overflow for help.

The assignment: Guestbook

1. Create a simple web page with PHP which displays “hello is it now: <the current date
and time>:
2. Commit your changes and push to master.
3. Checkout a new branch in git locally and keep on working in this branch.
4. Create a form for adding an entry in a guestbook. The form doesn’t need to do
anything yet. Give it the following form fields:
○ name
○ email
○ message
5. Now add some validation to the form so that when you submit it, validation errors are
shown. It does not have to be beautiful, as long as it works it’s good. Apply the
following validation rules:
○ name is required
○ email is required
○ message is required and should not be longer than 200 characters
6. Try to store the submitted and validated values in a JSON file on disk
○ hints: see file_put_contents, file_get_contents, json_encode and
json_decode
7. Try to display all entries from the JSON file on the page.
8. Try to store the entries in a database table instead of the JSON file.
9. Display all entries from the database table on the screen instead of the JSON file.
10. Great, the guestbook is finished now!
11. Push your new branch
12. Tryo to open a merge request, share the merge request with us on Slack.
13. We’ll review the code and maybe put some small comments/
14. Try to fix those, push your changes again.
15. Once everything is resolved you can merge the merge request.
16. Congratulations! Your first code is merged.

Bonus objectives (if you are done early):


1. Add validation so that only valid email addresses can be entered
2. Check your code for possible security issues:
a. try to escape the output so no JS and HTML can be injected
b. try to escape the queries to the database to prevent SQL injection
Assignment 2: PHP and the database part 2
1. Development needs to be done in the web directory
2. There is already a working PDO database connection. Check if it works (if there are
no errors).
3. Check if you can manage the database from PhpStorm as per instructions in the
README.
4. We will be creating some tables in the MySQL database, instructions how to do this
in PhpStorm: https://www.jetbrains.com/help/phpstorm/modify-table-dialog.html
5. Sometimes we need to create a foreign key, this page describes how to do this:
https://www.jetbrains.com/help/phpstorm/foreign-keys.html#create-a-foreign-key-in-a-
database
6. Start by creating a table in PhpStorm for shopping categories:
a. name: category
b. columns:
i. id, int, primary key, auto increment
ii. name, varchar(255), not null
7. Next we need a table for products
a. name products
b. columns:
i. id, int, primary key, auto increment
ii. name, varchar(255), not null
iii. price, decimal(15,2), not null
iv. categoryId, int, not null
c. Make categoryId a foreign key to category.id
8. We will be inserting some categories now
a. We need the Query console for this:
https://www.jetbrains.com/help/phpstorm/working-with-database-consoles.htm
l
b. Write some INSERT queries for categories: food, drinks, toppings
9. We will be inserting some products now:
a. Cola, € 25,50, category drinks
b. Water, € 0,95, category drinks
c. Fries, € 18,99, category food
d. Bread, € 5,23, category food
e. Apples, € 5,23, category food
f. Sugar, € 5,23, category toppings
10. Show all the categories on the index.php page
a. use https://www.php.net/manual/en/pdostatement.fetchall.php
b. Also add a link to a new page we will be creating product.php where we want
to show to product. We need to pass the product ID, so the link should look
like: /product.php?productId=1234
11. Create a new file called product.php in the web directory, this will be the product
detail page. Make sure to load the functions.php file and also setup the database
connection.
12. We will be receiving the productId in the URL, see how you can get that (hint: it is in
one of the superglobals)
13. Load the product from the database with
https://www.php.net/manual/en/pdostatement.fetch.php
14. Display the properties of the product on the page
15. Next we want to be able to search for products. We create a new search.php file in
the web directory.
16. We will link to the search page with the search term like this:
/search.php?term=Keyword
17. Create a LIKE query and fetch the results with PDO fetchAll
18. Display the results
19. Now we need a search form too. This will be added in index.php. Add a form there:
a. method of the form should be GET
b. add one text field with name term
c. action of the form should be /search.php
d. Once added the searching should be working
20. Nice you just built a simple webshop!
21. Bonus objectives: (only if you are ready within the time!)
a. Change the index page:
i. Use a <table> with <tr> and <td> for showing all products. The goal is
to have a table with a header row e.g.: name | price
And then below the rows with the data.
ii. Make it possible to sort the results by name ascending/descending if
you click on the header of table for name
iii. Make it possible to sort the results by price ascending/descending if
you click on the header of table for price
b. Create a form for adding new products
i. name should be unique
ii. price should be above 0 and below 100.000
c. Create a form for editing products (add an edit link in the table overview for
each row)
d. Create a link on the table for deleting products
Assignment 2: Apply object oriented programming to the
Guestbook
1. Create a new branch where you left off by the previous assignment.
2. Add an object that represents a guestbook entry. So a class named GuestbookEntry
with properties name, email and message. Don’t use the object yet.
3. Change your guestbook implementation so that you use the GuestbookEntry object:
- Create objects when you read from the database.
- Transform the objects to an array when writing to the database.
- Display the entries on the page while reading from the object properties.

4. Create an interface for storing and reading the guestbook entries:

interface GuestbookRepository {
public function readAll();
public function write(GuestBookEntry $guestbookEntry): void
}

5. Create one implementation for writing/reading from the JSON file


6. Create one implementation for writing/reading from the database
7. Create a class which will print the entries on the screen. Inject the
GuestbookRepository in the constructor.
8. Use this new class and see if you can get it working with the JSON implementation.
9. Change the implementation so that you inject the Database implementation.
10. Push your changes and open a merge request and ask for feedback.
11. Merge it once all comments are resolved.
Assignment 3: Add user and login
1. Create a new branch where you left off by the previous assignment.
2. Create a separate login page with login form, display a link to it on the homepage,
fields:
a. email
b. password.
3. Create logic that if the form is submitted, you validate the email and password. If the
username matches “admin” and password is “letmein”, we consider it valid and we
should log in the user.
a. hints: we need $_SESSION for this
b. hint: try to create objects here also
4. If the user is logged in, don’t show the link to the login page anymore. But show the
username instead.
5. Add a check on the homepage if the user is not logged in, we should redirect the user
to the login page.
a. hints: we need header for this
6. Add a new logout page. If someone visits this page, he/she is logged out.
7. Only show the link to the logout page on the homepage if the user is logged in.
8. Push your changes and open a merge request and ask for feedback.
9. Merge it once all comments are resolved.

Assignment 4: Add dynamic users

1. Create a new branch where you left off by the previous assignment.
2. If not already done in the previous assignment, create a User object which holds all
the properties for a user.
3. Create a database table for storing the users
4. Configure a few users manually in the table
a. can be done in a separate PHP file
b. or via a database tool like PhpMyAdmin, PHPStorm etc
5. Change the login validation so that it reads from the database instead of hardcoded
users.
6. Add a registration page with a form (doesn’t have to do anything yet):
a. email
b. password
7. Once submitted, validate:
a. email is required
b. password is required
8. If the form is valid, create a new user and redirect to the login page.
9. Try and see if the login is working
10. Storing passwords in plaintext is a security issue. Change the registration form and
login so that it is using hashed passwords.
a. hint: see password_hash and password_verify
11. Push your changes and open a merge request and ask for feedback.
12. Merge it once all comments are resolved.
Assignment 5: Namespaces and exceptions
1. In the code you currently have, try to implement namespacing for the classes.
2. In the code you currently have, try to create some exceptions and catch them
a. examples: if the user login fails, if the database connection fails etc

Assignment 6: Composer
1. Install composer locally

You might also like