├── LICENSE.txt ├── README.md └── course ├── 0 - Setup ├── Setup.pdf └── Setup.pptx ├── 1 - Basic Programming ├── Basic Programming.pptx ├── Lesson 1 - Data │ └── Examples │ │ ├── Example 1-1.php │ │ └── Example 1-2.php ├── Lesson 2 - Operators │ └── Examples │ │ ├── Example 2-1.php │ │ ├── Example 2-2.php │ │ └── Example 2-3.php ├── Lesson 3 - Functions │ └── Examples │ │ ├── Example 3-1.php │ │ ├── Example 3-2.php │ │ └── Example 3-3.php ├── Lesson 4 - Arrays │ └── Examples │ │ ├── Example 4-1.php │ │ ├── Example 4-2.php │ │ └── Example 4-3.php ├── Lesson 5 - Control Structures │ └── Examples │ │ ├── Example 5-1.php │ │ ├── Example 5-2.php │ │ └── Example 5-3.php ├── Lesson 6 - Objects and Classes │ └── Examples │ │ ├── Example 6-1.php │ │ ├── Example 6-2.php │ │ └── Example 6-3.php ├── Lesson 7 - Properties and Methods │ └── Examples │ │ ├── Example 7-1.php │ │ ├── Example 7-2.php │ │ └── Example 7-3.php ├── Lesson 8 - Files │ └── Examples │ │ ├── Example 8-1.php │ │ └── Example 8-2.php └── Lone Star 2015 │ ├── 1 - Variables │ ├── Examples │ │ └── Example 1-1.php │ └── Exercises │ │ ├── Exercise 1-1.md │ │ ├── Exercise 1-2.md │ │ ├── Sample 1-1.php │ │ └── Sample 1-2.php │ ├── 10 - Classes │ └── Examples │ │ ├── Example 11-1.php │ │ ├── Example 11-2.php │ │ └── Example 11-3.php │ ├── 11 - Properties │ └── Examples │ │ ├── Example 12-1.php │ │ └── Example 12-2.php │ ├── 2 - Basic Types │ ├── Examples │ │ ├── Example 2-1.php │ │ ├── Example 2-2.php │ │ ├── Example 2-3.php │ │ ├── Example 2-4.php │ │ ├── Example 2-5.php │ │ └── Example 2-6.php │ └── Exercises │ │ ├── Exercise 2-1.md │ │ ├── Exercise 2-2.md │ │ ├── Exercise 2-3.md │ │ ├── Sample 2-1.php │ │ ├── Sample 2-2.php │ │ └── Sample 2-3.php │ ├── 3 - Operators │ └── Examples │ │ ├── Example 3-1.php │ │ ├── Example 3-2.php │ │ ├── Example 3-3.php │ │ ├── Example 3-4.php │ │ ├── Example 3-5.php │ │ ├── Example 3-6.php │ │ ├── Example 3-7.php │ │ └── Example 3-8.php │ ├── 4 - Conditionals │ └── Examples │ │ ├── Example 4-1.php │ │ ├── Example 4-2.php │ │ ├── Example 4-3.php │ │ └── Example 4-4.php │ ├── 5 - Loops │ └── Examples │ │ ├── Example 5-1.php │ │ ├── Example 5-2.php │ │ └── Example 5-3.php │ ├── 6 - Functions │ └── Examples │ │ ├── Example 6-1.php │ │ ├── Example 6-2.php │ │ ├── Example 6-3.php │ │ └── Example 6-4.php │ ├── 7 - Files │ └── Examples │ │ ├── Example 8-1.php │ │ └── Example 8-2.php │ ├── 8 - Arrays │ └── Examples │ │ ├── Example 9-1.php │ │ ├── Example 9-2.php │ │ ├── Example 9-3.php │ │ └── Example 9-4.php │ ├── 9 - Objects │ └── Examples │ │ ├── Example 10-1.php │ │ ├── Example 10-2.php │ │ └── Example 10-3.php │ ├── Basics Of Programming.pdf │ └── Basics Of Programming.pptx ├── 2 - The Internet ├── The Internet.key ├── The Internet.pdf └── The Internet.pptx ├── 3 - Data and SQL ├── Data and SQL.key ├── Data and SQL.pdf └── Data and SQL.pptx ├── 4 - Organization and Projects ├── 1 - File Layout │ ├── application │ │ └── Lesson-1.md │ ├── examples │ │ ├── 1-1-config.php │ │ ├── 1-2-index.php │ │ ├── 1-3-notinjected.php │ │ ├── 1-4-injected.php │ │ ├── 1-5-autoloader.php │ │ ├── 1-5-usage.php │ │ └── Test.php │ └── exercises │ │ ├── Autoloader.php │ │ ├── Exercise-1.php │ │ └── Lesson-1.md ├── 2 - Data Models │ ├── application │ │ ├── Lesson-2.md │ │ └── Lesson-3.md │ ├── examples │ │ ├── 2-1-extendpdo.php │ │ ├── 2-2-injectpdo.php │ │ ├── 2-3-fetchobject.php │ │ ├── 2-4-fetchloop.php │ │ ├── 2-5-user.php │ │ └── 2-6-uservalidate.php │ └── exercises │ │ ├── Database-2.php │ │ ├── Database.php │ │ ├── Lesson-2.md │ │ └── PdoHelper.php ├── 3 - Views and Templates │ ├── examples │ │ ├── 3-1-template.html │ │ ├── 3-2-templateclass.php │ │ └── 3-3-useclass.php │ └── exercises │ │ ├── Lesson-3.md │ │ ├── Template.php │ │ ├── Template2.php │ │ ├── bad.html │ │ ├── basic.html │ │ ├── escape.html │ │ ├── exercise1.php │ │ └── exercise2.php └── Organization and Projects.pptx └── README.md /LICENSE.txt: -------------------------------------------------------------------------------- 1 | This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/4.0/ or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PHPEmbark 2 | 3 | PHPEmbark is an open-source curriculum package for instructors to use for teaching an introduction to PHP to beginners. 4 | 5 | No previous programming experience for students is required, and the teaching methods may not work as well for those with previous programming experience. 6 | 7 | This is not designed for "self" teaching, but around the concept of one or more instructors (either in person or using virtual tools) who are familar with the concepts leading the learning. 8 | 9 | ## License 10 | 11 | Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. 12 | 13 | ## Curriculum 14 | 15 | The curriculum is designed around a learning cycle of theory, example, practice, and application. 16 | 17 | This means a lesson begins with introduction of a theory, moves on to showing a practical example, the students perform one or more practice exercises, and then the newly aquired knowledge is applied toward building a practical application that can be run by the student. 18 | 19 | The sections are structured with "The Lego Rule" in mind - concepts are taught one at a time, and build on each other to expand knowledge, with an absolute minimum of "handwaving" or "magic". 20 | 21 | An attempt is made to reduce cognitive load by introducing only one new large skill per section. This means, for example, that no CLI experience or knowledge is assumed until the second half of the course. Instead the "refresh your browser" method of viewing output is used, and GUI tools are used for initial database interactions. 22 | 23 | ## Student Requirements 24 | 25 | - A computer running Windows 7 or 8, OS X 10.6 or newer, or a Linux variant (we will assume Ubuntu Desktop for the purposes of this course) 26 | - The ability to navigate the filesystem, including creating and deleting files and folders 27 | - The ability to download and install software on your computer 28 | 29 | ## Software used 30 | 31 | * [PHP 5.6](http://php.net) 32 | - We'll be using the built-in development HTTP server on port 8080 33 | - We will use SQLite databases 34 | - We will use PDO for database communication 35 | * [Komodo Edit](http://komodoide.com/komodo-edit/) 36 | - Komodo Edit is free, open source code editor that runs on all three platforms we are supporting 37 | - This exact tool is not a hard requirement, if students already have a text editor or IDE capable of PHP, HTML, and CSS highlighting and preferably with autocomplete for PHP, that known tool can be used instead for file editing. 38 | * A web browser, like Firefox or Google Chrome 39 | * [sqlite browser](http://sqlitebrowser.org/) 40 | - Free Open source GUI for dealing with sqlite databases that runs on all three platforms we are supporting 41 | 42 | ## Curriculum Outline 43 | 44 | Designed (except for Setup) in blocks of 1.5 to 2 hours, each section adds one 45 | large concept with multiple small lessons. At the end of the 16 hours a student 46 | should be at a level to work on or create basic PHP programs that talk to a 47 | database. The curriculum can be done in one or two day workshops (there is a 48 | natural break after section 4) or over a period of days or weeks online or at 49 | usergroups. Sections attempt to have a natural break at a half-way point for 50 | those restrained to 1 hour time slots. 51 | 52 | 0. Setup 53 | 1. Basic Programming 54 | 2. The Internet 55 | 3. Data and SQL 56 | 4. Organization and Projects 57 | 5. CLI Programming 58 | 6. Version Control 59 | 7. Composer and Libraries 60 | 8. Advanced OOP 61 | 62 | ## Resources 63 | 64 | As part of this curriculum, students will be walking through a stepped approach to building a journal application, while learning core concepts of developing with the PHP programming language. 65 | 66 | The full source of the journal application is provided at . Each branch in the repository represents a different lesson, each one building on the previous lessons. 67 | 68 | The curriculum also assumes a basic setup that is similar accross platforms and provides installation tools to achieve this setup. 69 | 70 | Students may download binaries for PHP, source code editors, and database tools, as well as zip packages of the journalapp lessons from the [releases page of the PHPEmbark/packages repository][release packages]. 71 | 72 | - **[Download latest packages][release packages]** 73 | 74 | 75 | ## Setup Concerns 76 | 77 | ### Windows 78 | All windows software will be available as a portable install - simply drop the zip file in place, extract the contents, open the resulting directory, and double click the included .bat file or the shorcut to the application that you want to run. 79 | 80 | Installers will also be available for windows for those wishing permanent installs of the software used, and instructions for downloading, configuring, installing, and running are also available. 81 | 82 | ## Mac OSX 83 | Easy installers are available for the sofware tools on OSX 84 | 85 | Newer versions of the operating system already have the correct PHP version installed. 86 | 87 | For older versions upgrades to PHP 5.6 should be done - possibly use http://php-osx.liip.ch ?? still under discussion 88 | 89 | ## Linux 90 | Because this is a beginner course, most Linux users will need to figure out their own way of setting up an environment, since those users tend to be more advanced. 91 | 92 | We will provide instructions for Ubuntu, which tends to be most commonly used for desktop linux systems. 93 | 94 | The software chosen is available as .deb packages for Ubuntu and is easy to install. Up to date PHP versions are readily available for Ubuntu as well, either as stock versions or by using available ppa's - instructions will also be provided for this. 95 | 96 | ## Teacher and Student Downloads 97 | Eventually we will have ready to go downloads for teachers (training, slides, how to present tips, handouts for printing, and helper notes), and students (examples, exercises, handouts for viewing, ready to run application) 98 | 99 | 100 | [release packages]: https://github.com/PHPEmbark/packages/releases/latest 101 | -------------------------------------------------------------------------------- /course/0 - Setup/Setup.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PHPEmbark/curriculum/138159cb393434e6208f21cc9348a0013f4b7411/course/0 - Setup/Setup.pdf -------------------------------------------------------------------------------- /course/0 - Setup/Setup.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PHPEmbark/curriculum/138159cb393434e6208f21cc9348a0013f4b7411/course/0 - Setup/Setup.pptx -------------------------------------------------------------------------------- /course/1 - Basic Programming/Basic Programming.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PHPEmbark/curriculum/138159cb393434e6208f21cc9348a0013f4b7411/course/1 - Basic Programming/Basic Programming.pptx -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lesson 1 - Data/Examples/Example 1-1.php: -------------------------------------------------------------------------------- 1 | 5; 9 | echo 10 <= 5; 10 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lesson 3 - Functions/Examples/Example 3-1.php: -------------------------------------------------------------------------------- 1 | "foo", 5 | 2 => "bar", 6 | "foobar" => 10, 7 | ]; 8 | 9 | echo $array[2]; 10 | 11 | var_dump($array); 12 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lesson 4 - Arrays/Examples/Example 4-2.php: -------------------------------------------------------------------------------- 1 | "foo", 5 | 2 => "bar", 6 | ]; 7 | 8 | $array[1] = "asdf"; 9 | $array[3] = 10; 10 | 11 | unset($array[2]); 12 | 13 | var_dump($array); 14 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lesson 4 - Arrays/Examples/Example 4-3.php: -------------------------------------------------------------------------------- 1 | $value) { 9 | echo $key; 10 | echo $value; 11 | } 12 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lesson 6 - Objects and Classes/Examples/Example 6-1.php: -------------------------------------------------------------------------------- 1 | property = "Properties are fun!" 11 | 12 | var_dump($object); 13 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lesson 7 - Properties and Methods/Examples/Example 7-2.php: -------------------------------------------------------------------------------- 1 | method(); 12 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lesson 7 - Properties and Methods/Examples/Example 7-3.php: -------------------------------------------------------------------------------- 1 | property; 7 | } 8 | } 9 | 10 | $object = new foobar(); 11 | 12 | $object->method(); 13 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lesson 8 - Files/Examples/Example 8-1.php: -------------------------------------------------------------------------------- 1 | 13 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/1 - Variables/Exercises/Exercise 1-1.md: -------------------------------------------------------------------------------- 1 | Exercise 1-1: Creating and Printing Variables 2 | 3 | # Create a blank PHP file and add the opening () tags. 4 | # Create a variable with any valid name (don't forget the $) and put a number in it. 5 | # Print the contents of the variable you just created using echo. 6 | 7 | Example output: 8 | 5 9 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/1 - Variables/Exercises/Exercise 1-2.md: -------------------------------------------------------------------------------- 1 | Exercise 1-2: Copying Variables 2 | 3 | # Create a variable called $var1 and put a number in it. 4 | # Copy $var1 to a new variable named $var2. 5 | # Print the contents of both variables using echo. 6 | 7 | Example output: 8 | 55 9 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/1 - Variables/Exercises/Sample 1-1.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/1 - Variables/Exercises/Sample 1-2.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/10 - Classes/Examples/Example 11-1.php: -------------------------------------------------------------------------------- 1 | 12 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/10 - Classes/Examples/Example 11-2.php: -------------------------------------------------------------------------------- 1 | 12 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/10 - Classes/Examples/Example 11-3.php: -------------------------------------------------------------------------------- 1 | 13 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/11 - Properties/Examples/Example 12-1.php: -------------------------------------------------------------------------------- 1 | 13 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/11 - Properties/Examples/Example 12-2.php: -------------------------------------------------------------------------------- 1 | property; 9 | $object->property = 'bar'; 10 | echo $object->property; 11 | 12 | ?> 13 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/2 - Basic Types/Examples/Example 2-1.php: -------------------------------------------------------------------------------- 1 | 10 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/2 - Basic Types/Examples/Example 2-2.php: -------------------------------------------------------------------------------- 1 | 10 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/2 - Basic Types/Examples/Example 2-3.php: -------------------------------------------------------------------------------- 1 | 10 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/2 - Basic Types/Examples/Example 2-4.php: -------------------------------------------------------------------------------- 1 | 10 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/2 - Basic Types/Examples/Example 2-5.php: -------------------------------------------------------------------------------- 1 | 9 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/2 - Basic Types/Examples/Example 2-6.php: -------------------------------------------------------------------------------- 1 | 12 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/2 - Basic Types/Exercises/Exercise 2-1.md: -------------------------------------------------------------------------------- 1 | Exercise 2-1: null and Boolean 2 | 3 | # Create a variable and store a Boolean in it. 4 | # Use echo to print two values which will produce no output. 5 | 6 | Example output: 7 | 8 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/2 - Basic Types/Exercises/Exercise 2-2.md: -------------------------------------------------------------------------------- 1 | Exercise 2-2: Numbers 2 | 3 | # Create a variable called $int and store an int (integer) in it. 4 | # Create another variable called $float and store a float in it. 5 | # Print the contents of both variables. 6 | 7 | Example output: 8 | 52.3 9 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/2 - Basic Types/Exercises/Exercise 2-3.md: -------------------------------------------------------------------------------- 1 | Exercise 2 | 3 | # 4 | 5 | Example output: 6 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/2 - Basic Types/Exercises/Sample 2-1.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/2 - Basic Types/Exercises/Sample 2-2.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/2 - Basic Types/Exercises/Sample 2-3.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/3 - Operators/Examples/Example 3-1.php: -------------------------------------------------------------------------------- 1 | 12 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/3 - Operators/Examples/Example 3-2.php: -------------------------------------------------------------------------------- 1 | 12 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/3 - Operators/Examples/Example 3-3.php: -------------------------------------------------------------------------------- 1 | 12 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/3 - Operators/Examples/Example 3-4.php: -------------------------------------------------------------------------------- 1 | 12 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/3 - Operators/Examples/Example 3-5.php: -------------------------------------------------------------------------------- 1 | 10 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/3 - Operators/Examples/Example 3-6.php: -------------------------------------------------------------------------------- 1 | 12 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/3 - Operators/Examples/Example 3-7.php: -------------------------------------------------------------------------------- 1 | 8; 8 | 9 | echo 7 <= 7; 10 | 11 | ?> 12 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/3 - Operators/Examples/Example 3-8.php: -------------------------------------------------------------------------------- 1 | 12 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/4 - Conditionals/Examples/Example 4-1.php: -------------------------------------------------------------------------------- 1 | 16 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/4 - Conditionals/Examples/Example 4-2.php: -------------------------------------------------------------------------------- 1 | 16 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/4 - Conditionals/Examples/Example 4-3.php: -------------------------------------------------------------------------------- 1 | 14 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/4 - Conditionals/Examples/Example 4-4.php: -------------------------------------------------------------------------------- 1 | 13 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/5 - Loops/Examples/Example 5-1.php: -------------------------------------------------------------------------------- 1 | 11 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/5 - Loops/Examples/Example 5-2.php: -------------------------------------------------------------------------------- 1 | 11 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/5 - Loops/Examples/Example 5-3.php: -------------------------------------------------------------------------------- 1 | 10 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/6 - Functions/Examples/Example 6-1.php: -------------------------------------------------------------------------------- 1 | 12 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/6 - Functions/Examples/Example 6-2.php: -------------------------------------------------------------------------------- 1 | 12 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/6 - Functions/Examples/Example 6-3.php: -------------------------------------------------------------------------------- 1 | 12 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/6 - Functions/Examples/Example 6-4.php: -------------------------------------------------------------------------------- 1 | 11 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/7 - Files/Examples/Example 8-1.php: -------------------------------------------------------------------------------- 1 | 8 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/7 - Files/Examples/Example 8-2.php: -------------------------------------------------------------------------------- 1 | 12 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/8 - Arrays/Examples/Example 9-1.php: -------------------------------------------------------------------------------- 1 | 12 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/8 - Arrays/Examples/Example 9-2.php: -------------------------------------------------------------------------------- 1 | 'foo', 5 | '3' => 'bar', 6 | 'abc' => 123, 7 | false => 'asdf', 8 | ]; 9 | var_dump( $array ); 10 | 11 | ?> 12 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/8 - Arrays/Examples/Example 9-3.php: -------------------------------------------------------------------------------- 1 | 13 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/8 - Arrays/Examples/Example 9-4.php: -------------------------------------------------------------------------------- 1 | $value) { 8 | echo $key . $value; 9 | } 10 | 11 | ?> 12 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/9 - Objects/Examples/Example 10-1.php: -------------------------------------------------------------------------------- 1 | 11 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/9 - Objects/Examples/Example 10-2.php: -------------------------------------------------------------------------------- 1 | 12 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/9 - Objects/Examples/Example 10-3.php: -------------------------------------------------------------------------------- 1 | 12 | -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/Basics Of Programming.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PHPEmbark/curriculum/138159cb393434e6208f21cc9348a0013f4b7411/course/1 - Basic Programming/Lone Star 2015/Basics Of Programming.pdf -------------------------------------------------------------------------------- /course/1 - Basic Programming/Lone Star 2015/Basics Of Programming.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PHPEmbark/curriculum/138159cb393434e6208f21cc9348a0013f4b7411/course/1 - Basic Programming/Lone Star 2015/Basics Of Programming.pptx -------------------------------------------------------------------------------- /course/2 - The Internet/The Internet.key: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PHPEmbark/curriculum/138159cb393434e6208f21cc9348a0013f4b7411/course/2 - The Internet/The Internet.key -------------------------------------------------------------------------------- /course/2 - The Internet/The Internet.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PHPEmbark/curriculum/138159cb393434e6208f21cc9348a0013f4b7411/course/2 - The Internet/The Internet.pdf -------------------------------------------------------------------------------- /course/2 - The Internet/The Internet.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PHPEmbark/curriculum/138159cb393434e6208f21cc9348a0013f4b7411/course/2 - The Internet/The Internet.pptx -------------------------------------------------------------------------------- /course/3 - Data and SQL/Data and SQL.key: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PHPEmbark/curriculum/138159cb393434e6208f21cc9348a0013f4b7411/course/3 - Data and SQL/Data and SQL.key -------------------------------------------------------------------------------- /course/3 - Data and SQL/Data and SQL.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PHPEmbark/curriculum/138159cb393434e6208f21cc9348a0013f4b7411/course/3 - Data and SQL/Data and SQL.pdf -------------------------------------------------------------------------------- /course/3 - Data and SQL/Data and SQL.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PHPEmbark/curriculum/138159cb393434e6208f21cc9348a0013f4b7411/course/3 - Data and SQL/Data and SQL.pptx -------------------------------------------------------------------------------- /course/4 - Organization and Projects/1 - File Layout/application/Lesson-1.md: -------------------------------------------------------------------------------- 1 | # Section 4 - Organization and Projects 2 | 3 | ## Lesson 1 - File Layout and Organization 4 | 5 | ## Practical Application 6 | 7 | We've learned about practial considerations when deciding how to organize a PHP application. We've learned that there is a folder structure that most projects follow. 8 | We've learned how separating our code up into areas helps make it easier to add new features, and we've learned that keeping things out of our docroot is important. 9 | 10 | We're going to create a new directory for our journal application with a fresh layout. We'll move all the pieces we've written in our other sections into our 11 | new directory and we'll also incorporate bootstrap to make our site look nice. 12 | 13 | ## Steps to Take 14 | 15 | 1. Create a new directory to hold our journal application 16 | 2. Create a directory structure with a public directory, src directory, data directory, and config directory 17 | 18 | ### Data directory 19 | 20 | This is where we'll store our sqlite database, and our schema.sql file that we built up in previous sections 21 | 22 | 1. Move the journal.sqlite file into the /data directory 23 | 2. Move the schema.sql file into the /data directory 24 | 25 | ### Config directory 26 | 27 | This is where we'll store configuration information for our application 28 | 29 | 1. Create an empty config.php file in the /config directory 30 | 2. Make the config file return an empty array 31 | 32 | ### Public directory 33 | 34 | This is where our web facing files go 35 | 36 | 1. Move our form related php files from section 2 into /public 37 | 2. Move our database php files from section 3 into /public 38 | 3. Grab the minimal bootstrap installation files from bootstrap.com or the downloaded package and place them in your public directory - we'll use these later to make our site look nice 39 | 4. Create an "index.php" file and fetch your configuration file with it 40 | 41 | ### Src directory 42 | 43 | We're going to reorganize not only our files, but also pull pieces out of our code to make it easier to work with 44 | The src directory will be the place where we end up storing our classes that do work 45 | 46 | 1. Create a 'Journal' directory 47 | 2. Move our 'Autoloader' class from our exercises into the Journal directory 48 | 3. Put the Autoloader in the Journal namespace 49 | 4. include and register it in your index.php -------------------------------------------------------------------------------- /course/4 - Organization and Projects/1 - File Layout/examples/1-1-config.php: -------------------------------------------------------------------------------- 1 | 'value', 4 | ]; -------------------------------------------------------------------------------- /course/4 - Organization and Projects/1 - File Layout/examples/1-2-index.php: -------------------------------------------------------------------------------- 1 | 'name', 'value' => 'value']; 3 | 4 | class NotInjected { 5 | public function __construct($config) 6 | { 7 | $this->name = $config['name']; 8 | $this->value = $config['value']; 9 | } 10 | } 11 | 12 | $object = new NotInjected($config); 13 | var_dump($object); -------------------------------------------------------------------------------- /course/4 - Organization and Projects/1 - File Layout/examples/1-4-injected.php: -------------------------------------------------------------------------------- 1 | 'name', 'value' => 'value']; 3 | 4 | class Injected { 5 | public function __construct($name, $value) 6 | { 7 | $this->name = $name; 8 | $this->value = $value; 9 | } 10 | } 11 | 12 | $object = new Injected($config['name'], $config['value']); 13 | var_dump($object); -------------------------------------------------------------------------------- /course/4 - Organization and Projects/1 - File Layout/examples/1-5-autoloader.php: -------------------------------------------------------------------------------- 1 | classPath = $class_path; 9 | } 10 | 11 | public function load($class_name) 12 | { 13 | $file = $this->classPath . '/' . str_replace("\\", "/", $class_name) . '.php'; 14 | 15 | if (file_exists($file)) { 16 | require $file; 17 | } else { 18 | return false; 19 | } 20 | } 21 | 22 | public function register() 23 | { 24 | spl_autoload_register([$this, 'load']); 25 | } 26 | } -------------------------------------------------------------------------------- /course/4 - Organization and Projects/1 - File Layout/exercises/Exercise-1.php: -------------------------------------------------------------------------------- 1 | name = $name; 10 | $this->age = $age; 11 | $this->haircolor = $haircolor; 12 | } 13 | } 14 | 15 | $storage = ['name' => 'Sally', 'age' => 15, 'haircolor' => 'red']; 16 | var_dump(new Person($storage['name'], $storage['age'], $storage['haircolor'])); 17 | 18 | $storage = newstdclass; 19 | $storage->name = 'Lucy'; 20 | $storage->age = '12'; 21 | $storage->haircolor = 'brown'; 22 | var_dump(new Person($storage->name, $storage->age, $storage->haircolor)); 23 | 24 | $name = 'Fred'; 25 | $age = '26'; 26 | $haircolor = 'black'; 27 | var_dump(new Person($name, $age, $haircolor)); -------------------------------------------------------------------------------- /course/4 - Organization and Projects/1 - File Layout/exercises/Lesson-1.md: -------------------------------------------------------------------------------- 1 | # Section 4 - Organization and Projects 2 | 3 | ## Lesson 1 - File Layout and Organization 4 | 5 | ## Practial Application 6 | 7 | Most of the items we've learned about don't have a lot of code associated with them. 8 | We've learned concepts of file layout, the imporatnce of keeping stuff out of our docroot, and started on the idea of separating 9 | parts of our code. 10 | 11 | But we do have a few concepts we can work on 12 | 13 | ### Concepts of Dependency Injection 14 | 15 | Exercise 1: 16 | 17 | 1. Create an object that holds three different properties 18 | 2. Create one script that stores those properties in an object and passes them in 19 | 3. Create one script that stores those properties in an array and passes them in 20 | 4. Create one script that stores those values in variables and passes them in 21 | 5. What are other ways the data might be stored? 22 | - Databases 23 | - Ini Files 24 | - Json 25 | 26 | ### Using and Writing Autoloaders 27 | 28 | Exercise 2: 29 | 30 | 1. Write an autoloader class 31 | 2. Allow the autoloader class to store a base path where it will look for classes 32 | 3. Write a register class that the autoloader can use to put itself on the spl_autoload_register stack 33 | 4. Write a load class that replaces backslashes in a name with forward slashes - this will make namespaces act like directory separators -------------------------------------------------------------------------------- /course/4 - Organization and Projects/2 - Data Models/application/Lesson-2.md: -------------------------------------------------------------------------------- 1 | # Section 4 - Organization and Projects 2 | 3 | ## Lesson 2 - Data Models And Validation 4 | 5 | ## Practical Application 6 | 7 | We've talked about separating our code that talks to our data out from our other code. We've talked about consolidating our 8 | data from our database into an object, with some rules for what the data should contain. 9 | 10 | ## Steps to Take 11 | 12 | 1. Create a basic database class we will inject into our other classes 13 | 2. Create two classes to consolidate our communication with the database 14 | 3. Create two classes to define what our data should look like 15 | 16 | ### Base PDO class 17 | 18 | Let's create a "base class" for our database connection, that extends the PDO class 19 | 20 | 1. Create a class that extends PDO in a Journal namespace 21 | - hint: remember to use any class at the top of your file 22 | 2. Allow it to take a $db_path and a $db_file parameters 23 | 3. Create the proper string to talk to the database, and store it 24 | 4. Make sure you turn exceptions on for pdo 25 | 5. Add db_path and db_file into our configuration, create the db class in our index.php using those values 26 | 27 | ### Database Classes 28 | 29 | In section 3 we learned to perform basic sql queries, and we've already created some classes with basic 30 | functionality to insert, update, delete and list entries, edit a user, get a user, and verify a password for a user. 31 | 32 | Now we'll change those classes 33 | 1. Move Users.php and Entries.php into /src/Journal/Model 34 | 2. Add the Journal\Model namespace to both 35 | 3. Instead of creating their own connection, allow a Journal\DB instance to be injected 36 | 37 | ### Data Object 38 | 39 | This is the first real code you'll need to write 40 | 41 | 1. Create a User.php and an Entry.php class in /src/Journal/Model 42 | 2. Allow an array to be passed in optionally and use it to set properties in the class 43 | - this will be helpful when we tie our data in with form submits 44 | 3. Create public properties for all our data columns 45 | 4. Take the validate edit and validate create functions we wrote with forms, and copy them into these classes 46 | 5. Have them use the class properties instead of data in an array to validate the information 47 | 48 | ### Integrating data objects and the data classes 49 | 1. Change the insert and update functions in Entries.php and Users.php to accept either User or Entry classes, instead of arrays use properties to assign values for binding. 50 | 2. Use PDO fetchObject with a classname for fetching single items, and use PDO::setFetchMode with object and a classname to make sure you're returning your new data objects -------------------------------------------------------------------------------- /course/4 - Organization and Projects/2 - Data Models/application/Lesson-3.md: -------------------------------------------------------------------------------- 1 | # Section 4 - Organization and Projects 2 | 3 | ## Lesson 3 - Views And Templates 4 | 5 | ## Practical Application 6 | 7 | Templating and using the idea of "view" being separated from data and logic will allow us to have a common look and feel 8 | and keep our html isolated from the rest of our application. 9 | 10 | ## Steps to Take 11 | 12 | 1. Pull our existing forms into separate html template files 13 | 2. Create a common html "base" file so we have a consistent look for all our logic 14 | 3. Create a base template class with some helpers 15 | 4. Create our template object and allow it to be "injected" into our code 16 | 17 | ### Pull out existing forms 18 | 19 | In section 2 we created some forms that had accompanying validation. We've already moved the validation in the last lesson. 20 | In this lesson we'll move the html 21 | 22 | 1. Create an /src/Journal/View/tpl directory, we'll consolidate all our views here 23 | 2. Create a users directory inside - here we'll have 2 forms, our login form and our profile edit form 24 | - copy the html from those two forms 25 | - change the echos - for example use $this->user->display instead of $user['display'] 26 | 3. Create a entries directory parallel to users - here we'll have 3 forms and a list page 27 | - copy the html for the create, edit, and delete html from create.php, edit.php, and delete.php 28 | - copy the html for the list.php 29 | 30 | Make sure all our forms use the database items 31 | 32 | ### Create our Base HTML 33 | 34 | We're going to create a common piece of html to use for all pages, and we'll call a method called "content" 35 | for individual pages to get the data they need 36 | 37 | 1. create a file in /src/Journal/View/tpl called base.html 38 | 2. Copy the basic html format from our "using boostrap" example 39 | 3. Where the content should go, add content(); ?> 40 | 41 | ### Create our base template class 42 | 43 | Create a new class in the Journal namespace, put it next to your Db.php file in /src/Journal 44 | 45 | 1. Base it off of your class for our templates exercise 46 | 2. Make sure you can send it a base location for templates, and a name of a default "base" template in the constructor 47 | 3. Make sure it has an escapeHtml() method 48 | 4. Add a wrapText() method that does a nl2br on data sent to it, this will create nicely formatted posts. Make sure it ALSO escapes any data 49 | 5. Add a "content" method that includes whatever template name is set 50 | 6. In your render method, instead of including the passed template, save it for content, and include the base template instead 51 | 52 | ### Creating and using our template object 53 | 1. Add our template settings to config 54 | 2. Create a template object in index.php to be used -------------------------------------------------------------------------------- /course/4 - Organization and Projects/2 - Data Models/examples/2-1-extendpdo.php: -------------------------------------------------------------------------------- 1 | setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 9 | } 10 | } -------------------------------------------------------------------------------- /course/4 - Organization and Projects/2 - Data Models/examples/2-2-injectpdo.php: -------------------------------------------------------------------------------- 1 | db = $db; 9 | } 10 | 11 | public function fetchAll() { 12 | $this->db->query('SELECT * FROM user'); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /course/4 - Organization and Projects/2 - Data Models/examples/2-3-fetchobject.php: -------------------------------------------------------------------------------- 1 | prepare($sql); 7 | $stmt->execute(); 8 | $stmt->fetchObject('User'); -------------------------------------------------------------------------------- /course/4 - Organization and Projects/2 - Data Models/examples/2-4-fetchloop.php: -------------------------------------------------------------------------------- 1 | prepare($sql); 7 | $stmt->execute(); 8 | $stmt->setFetchMode(Db::FETCH_CLASS, 'User'); 9 | 10 | foreach($stmt as $user_object) {} 11 | -------------------------------------------------------------------------------- /course/4 - Organization and Projects/2 - Data Models/examples/2-5-user.php: -------------------------------------------------------------------------------- 1 | user_id)) { 10 | return false; 11 | } 12 | 13 | return true; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /course/4 - Organization and Projects/2 - Data Models/exercises/Database-2.php: -------------------------------------------------------------------------------- 1 | data)) { 8 | return false; 9 | } 10 | if(!empty($this->test_id)) { 11 | return false; 12 | } 13 | 14 | return true; 15 | } 16 | 17 | public function validateUpdate() { 18 | if(empty($data)) { 19 | return false 20 | } 21 | if(empty($this->test_id)) { 22 | return false; 23 | } 24 | 25 | return true; 26 | } 27 | } 28 | 29 | class Database { 30 | 31 | protected $db = null; 32 | protected $ddl = ' 33 | CREATE TABLE `Test` ( 34 | `test_id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 35 | `data` TEXT NOT NULL 36 | ); 37 | '; 38 | 39 | public function __construct() 40 | { 41 | $this->db = new Pdo('sqlite::memory:'); 42 | $this->db->exec($this->ddl); 43 | } 44 | 45 | public function insert(Test $data) 46 | { 47 | if(!$data->validateInsert()) { 48 | return false; 49 | } 50 | 51 | $sql = 52 | 'INSERT INTO test ( 53 | data 54 | ) VALUES ( 55 | :data 56 | )'; 57 | 58 | $bind = [ 59 | ':data' => $data->data, 60 | ]; 61 | 62 | $query = $this->db->prepare($sql); 63 | $status = $query->execute($bind); 64 | 65 | $data->test_id = $this->db->lastInsertId(); 66 | 67 | return $status; 68 | } 69 | 70 | public function update(Test $data) 71 | { 72 | if(!$data->validateUpdate()) { 73 | return false; 74 | } 75 | 76 | $sql = 77 | 'UPDATE test 78 | SET 79 | data = :data 80 | WHERE 81 | test_id = :test_id'; 82 | 83 | $bind = [ 84 | ':data' => $data->data, 85 | ':test_id' => $data->test_id, 86 | ]; 87 | 88 | $query = $this->db->prepare($sql); 89 | return $query->execute($bind); 90 | } 91 | 92 | public function delete($id) 93 | { 94 | $sql = 95 | 'DELETE FROM test 96 | WHERE 97 | test_id = :test_id'; 98 | 99 | $bind = [ 100 | ':test_id' => $id, 101 | ]; 102 | 103 | $query = $this->db->prepare($sql); 104 | return $query->execute($bind); 105 | } 106 | 107 | public function getItem($id) 108 | { 109 | $sql = 110 | 'SELECT test_id 111 | data 112 | FROM test 113 | WHERE test_id = :test_id LIMIT 1'; 114 | 115 | $bind = [ 116 | ':test_id' => $id, 117 | ]; 118 | 119 | $query = $this->db->prepare($sql); 120 | $query->execute($bind); 121 | 122 | return $query->fetchObject('Test'); 123 | } 124 | 125 | public function getAll() 126 | { 127 | $sql = 128 | 'SELECT test_id, 129 | data 130 | FROM test 131 | ORDER BY test_id DESC'; 132 | 133 | $query = $this->db->prepare($sql); 134 | $query->execute(); 135 | $query->setFetchMode(Db::FETCH_CLASS, 'Test'); 136 | 137 | return $query; 138 | } 139 | } -------------------------------------------------------------------------------- /course/4 - Organization and Projects/2 - Data Models/exercises/Database.php: -------------------------------------------------------------------------------- 1 | db = new Pdo('sqlite::memory:'); 15 | $this->db->exec($this->ddl); 16 | } 17 | 18 | public function insert($data) 19 | { 20 | $sql = 21 | 'INSERT INTO test ( 22 | data 23 | ) VALUES ( 24 | :data 25 | )'; 26 | 27 | $bind = [ 28 | ':data' => $data, 29 | ]; 30 | 31 | $query = $this->db->prepare($sql); 32 | $query->execute($bind); 33 | 34 | return $this->db->lastInsertId(); 35 | } 36 | 37 | public function update($test_id, $data) 38 | { 39 | $sql = 40 | 'UPDATE test 41 | SET 42 | data = :data 43 | WHERE 44 | test_id = :test_id'; 45 | 46 | $bind = [ 47 | ':data' => $data, 48 | ':test_id' => $test_id, 49 | ]; 50 | 51 | $query = $this->db->prepare($sql); 52 | return $query->execute($bind); 53 | } 54 | 55 | public function delete($id) 56 | { 57 | $sql = 58 | 'DELETE FROM test 59 | WHERE 60 | test_id = :test_id'; 61 | 62 | $bind = [ 63 | ':test_id' => $id, 64 | ]; 65 | 66 | $query = $this->db->prepare($sql); 67 | return $query->execute($bind); 68 | } 69 | 70 | public function getItem($id) 71 | { 72 | $sql = 73 | 'SELECT test_id 74 | data 75 | FROM test 76 | WHERE test_id = :test_id LIMIT 1'; 77 | 78 | $bind = [ 79 | ':test_id' => $id, 80 | ]; 81 | 82 | $query = $this->db->prepare($sql); 83 | $query->execute($bind); 84 | 85 | return $query->fetchAssoc(); 86 | } 87 | 88 | public function getAll() 89 | { 90 | $sql = 91 | 'SELECT test_id, 92 | data 93 | FROM test 94 | ORDER BY test_id DESC'; 95 | 96 | $query = $this->db->prepare($sql); 97 | $query->execute(); 98 | 99 | return $query; 100 | } 101 | } -------------------------------------------------------------------------------- /course/4 - Organization and Projects/2 - Data Models/exercises/Lesson-2.md: -------------------------------------------------------------------------------- 1 | # Section 4 - Organization and Projects 2 | 3 | ## Lesson 2 - Data Models and Validation 4 | 5 | ## Practical Application 6 | 7 | We've gone over several concepts 8 | 9 | ### Extending PDO 10 | 11 | Exercise 1: 12 | 13 | 1. Create a class that extends PDO 14 | 2. Create a constructor that manipulates arguments into a new dsn 15 | 3. Create a "helper" function that will store all queries sent to pdo 16 | 4. Create a "helper" function that will retreive those stored queries 17 | - how could this help with debugging or making database queries work better? 18 | 19 | ### Writing Database Access Objects 20 | 21 | Exercise 2: 22 | 23 | 1. Create your own database table sql with 2 columns 24 | 2. Create a CRUD database access class for your new database table 25 | 26 | ### Writing Data Objects 27 | 28 | Exercise 3: 29 | 30 | 1. Create a data object for your new database table 31 | 2. Create a validation method for your data object 32 | 3. Make your Database Access Object use your new Data Object -------------------------------------------------------------------------------- /course/4 - Organization and Projects/2 - Data Models/exercises/PdoHelper.php: -------------------------------------------------------------------------------- 1 | dsn = 'sqlite:' . $path . '/' . $filename . '.sqlite'; 11 | parent::__construct($this->dsn); 12 | $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 13 | } 14 | 15 | public function exec($statement) { 16 | $this->queries[] = $statement; 17 | return parent::exec($statement); 18 | } 19 | 20 | public function query($statement) { 21 | $this->queries[] = $statement; 22 | return parent::query($statement); 23 | } 24 | 25 | public function prepare($statement) { 26 | $this->queries[] = $statement; 27 | return parent::prepare($statement); 28 | } 29 | 30 | public function getQueries() { 31 | return $this->queries; 32 | } 33 | } -------------------------------------------------------------------------------- /course/4 - Organization and Projects/3 - Views and Templates/examples/3-1-template.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | <?= $this->title ?> 5 | 6 | 7 |
8 | message ?> 9 |
10 | 11 | -------------------------------------------------------------------------------- /course/4 - Organization and Projects/3 - Views and Templates/examples/3-2-templateclass.php: -------------------------------------------------------------------------------- 1 | $value) { 6 | $this->{$key} = $value; 7 | } 8 | 9 | require __DIR__ . '/' . $tpl; 10 | } 11 | } -------------------------------------------------------------------------------- /course/4 - Organization and Projects/3 - Views and Templates/examples/3-3-useclass.php: -------------------------------------------------------------------------------- 1 | $value) { 6 | $this->{$key} = $value; 7 | } 8 | 9 | require __DIR__ . '/' . $tpl; 10 | } 11 | } 12 | 13 | $vars = [ 14 | 'title' => 'Hello and Welcome', 15 | 'message' => 'This is my templated application', 16 | ]; 17 | 18 | $template = new Template; 19 | $template->render('3-1-template.html', $vars); -------------------------------------------------------------------------------- /course/4 - Organization and Projects/3 - Views and Templates/exercises/Lesson-3.md: -------------------------------------------------------------------------------- 1 | # Section 4 - Organization and Projects 2 | 3 | ## Lesson 3 - Views and Templates 4 | 5 | ## Practical Application 6 | 7 | We've learned how it's useful to keep all of our html in one place, and out of our PHP files. 8 | We've also learned how 9 | 10 | ### Writing a Template Class 11 | 12 | Exercise 1: 13 | 14 | 1. Create a template class 15 | 2. Make sure it can accept a template location in the constructor 16 | 3. Give it a render method that can include a PHP file 17 | 4. Remember scope! The template will have access to everything in the class, and variables in your method! Create an example that echos that information. 18 | 5. Create a template file and use your template class to display it twice, with different information 19 | 20 | ### Escaping is Important! 21 | 22 | Exercise 2: 23 | 24 | 1. Use your template class in another example, this time create a variable with some html inside 25 | 2. Create an escapeHtml method that properly escapes output for html 26 | 3. Use that inside a template with the same data -------------------------------------------------------------------------------- /course/4 - Organization and Projects/3 - Views and Templates/exercises/Template.php: -------------------------------------------------------------------------------- 1 | location = $location; 7 | } 8 | 9 | public function render($tpl, $data = array()) 10 | { 11 | foreach ($data as $key => $value) { 12 | $this->{$key} = $value; 13 | } 14 | 15 | require $this->location . '/' . $tpl; 16 | } 17 | } -------------------------------------------------------------------------------- /course/4 - Organization and Projects/3 - Views and Templates/exercises/Template2.php: -------------------------------------------------------------------------------- 1 | location = $location; 7 | } 8 | 9 | public function render($tpl, $data = array()) 10 | { 11 | foreach ($data as $key => $value) { 12 | $this->{$key} = $value; 13 | } 14 | 15 | require $this->location . '/' . $tpl; 16 | } 17 | 18 | public function escapeHtml($data) 19 | { 20 | return htmlspecialchars($data, ENT_COMPAT, 'UTF-8'); 21 | } 22 | } -------------------------------------------------------------------------------- /course/4 - Organization and Projects/3 - Views and Templates/exercises/bad.html: -------------------------------------------------------------------------------- 1 |

Bad

2 |
3 |
4 |
5 |
6 |
7 |                 
8 |             
9 |
-------------------------------------------------------------------------------- /course/4 - Organization and Projects/3 - Views and Templates/exercises/basic.html: -------------------------------------------------------------------------------- 1 |

Basic

2 |
3 | message ?> 4 |
-------------------------------------------------------------------------------- /course/4 - Organization and Projects/3 - Views and Templates/exercises/escape.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | <?= $this->title ?> 5 | 6 | 7 |
8 | message ?> 9 |
10 |
11 | escapeHtml($this->message) ?> 12 |
13 | 14 | -------------------------------------------------------------------------------- /course/4 - Organization and Projects/3 - Views and Templates/exercises/exercise1.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Bad Dump 5 | 6 | 7 | render('bad.html'); 13 | 14 | $template->render('basic.html', ['message' => 'hello']); 15 | $template->render('basic.html', ['message' => 'world']); 16 | ?> 17 | 18 | -------------------------------------------------------------------------------- /course/4 - Organization and Projects/3 - Views and Templates/exercises/exercise2.php: -------------------------------------------------------------------------------- 1 | To boldly go!'; 7 | 8 | $template->render('escape.html', ['message' => $string, 9 | 'escaped' => $string]); -------------------------------------------------------------------------------- /course/4 - Organization and Projects/Organization and Projects.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PHPEmbark/curriculum/138159cb393434e6208f21cc9348a0013f4b7411/course/4 - Organization and Projects/Organization and Projects.pptx -------------------------------------------------------------------------------- /course/README.md: -------------------------------------------------------------------------------- 1 | # Course Syllabus 2 | 3 | Except for the Introduction and Setup, which should run no more than 10 or 15 minutes each section of is designed to be a 2 hour course, with a logical break halfway. 4 | 5 | Each section provides materials for presenting (slides with notes) for teachers, handouts (written materials suitable for printing out or reading on screen) for students, a directory of exercises to enhance learning, and a directory with a hands on exercise that will lead to a practical application of the new skill in an overall project. 6 | 7 | There are 8 sections - 16 hours of teaching material, and that barely scratches the surface of all there is to be learned in programming PHP. 8 | 9 | This can be taught over multiple days or weeks in one or two hour sessions, or in day long workshops typical of conferences. 10 | 11 | Only the first half is currently completed 12 | 13 | ### Idea outline: 14 | 15 | 1. open source slides (do we have a format preference for this? some 16 | like powerpoint, some keynote, there are other solutions, but whatever 17 | we use needs to be simple) in one hour "block" setups with notes for 18 | presenters/teachers to use - this will allow the talks to be done as 19 | a "series" at usergroups, tutorials and workshops at conferences, and 20 | even online via online presentation methods 21 | 22 | For now I'm just doing powerpoint slides - they are really simple and can be exported to other formats, but it's important to have the original version available for editing 23 | 24 | In additional all code shown should have available .php files in examples directories 25 | 26 | 2. written handout/textbook style information for learners - basically written versions of the slides 27 | 28 | 3. quiz/exercise style questions to "solve" - to practice new skills - 29 | possibly with example solutions or even without 30 | 31 | 4. Practical usage that when put together creates a completed application 32 | 33 | The practical part will probably need to be written BACKWARDS - since 34 | we'll have a final simplistic application that then gets torn apart to 35 | learn little pieces at a time. I'd like to keep the 36 | javascript/css/html burden to as little as possible, although if 37 | someone with more design skills would like to provide a "plug and 38 | play" solution for adding pretty design to our finished practical app, 39 | that's fine. 40 | 41 | As for what to write as the final practial application I don't really 42 | care too much. I was considering a simple user free form diary. Then 43 | we could implement a single user login/logout, posting of content, 44 | getting of content in list and single entry format. And it would be 45 | just fine with sqlite as the db :) 46 | 47 | Best practices should be shown always (you teach sql use + prepared 48 | statements, htmlentities with $_GET and $_POST) but stay away from 49 | additional complex concepts 50 | 51 | since we're already teaching 52 | http and internet 53 | php programming 54 | sql 55 | very basic mvc/project layout 56 | 57 | we need to attempt to keep the "learning load" down 58 | 59 | Part 2 will be additional load and not finished right away 60 | version control 61 | cli 62 | javascript 63 | composer and library usage 64 | advanced OOP 65 | advanced html/css 66 | 67 | later we can add those as additional things to learn --------------------------------------------------------------------------------