From b761690292e1fb72dbec95941ada58ff8f6b83e3 Mon Sep 17 00:00:00 2001 From: Jonathan Reinink Date: Fri, 25 Jul 2014 14:53:02 -0400 Subject: [PATCH] Add new Templating section. --- ...de.md => 07-02-01-Interacting-via-Code.md} | 2 +- ...yers.md => 07-03-01-Abstraction-Layers.md} | 2 +- _posts/08-01-01-Templating.md | 12 ++++++++ _posts/08-02-01-Benefits.md | 21 ++++++++++++++ _posts/08-03-01-Plain-PHP-Templates.md | 28 +++++++++++++++++++ _posts/08-04-01-Compiled-Templates.md | 28 +++++++++++++++++++ _posts/08-05-01-Further-Reading.md | 27 ++++++++++++++++++ ...s.md => 09-01-01-Errors-and-Exceptions.md} | 0 ...{08-02-01-Errors.md => 09-02-01-Errors.md} | 0 ...1-Exceptions.md => 09-03-01-Exceptions.md} | 0 ...01-01-Security.md => 10-01-01-Security.md} | 0 ...d => 10-02-01-Web-Application-Security.md} | 0 ...ashing.md => 10-03-01-Password-Hashing.md} | 0 ...iltering.md => 10-04-01-Data-Filtering.md} | 0 ...les.md => 10-05-01-Configuration-Files.md} | 0 ...lobals.md => 10-06-01-Register-Globals.md} | 0 ...porting.md => 10-07-01-Error-Reporting.md} | 0 ...0-01-01-Testing.md => 11-01-01-Testing.md} | 0 ...md => 11-02-01-Test-Driven-Development.md} | 0 ...> 11-03-01-Behavior-Driven-Development.md} | 0 ...> 11-04-01-Complementary-Testing-Tools.md} | 0 ....md => 12-01-01-Servers-and-Deployment.md} | 0 ...e.md => 12-02-01-Platform-as-a-Service.md} | 0 ... 12-03-01-Virtual-or-Dedicated-Servers.md} | 0 ...-Servers.md => 12-04-01-Shared-Servers.md} | 0 ... => 12-05-01-Building-your-Application.md} | 0 ...2-01-01-Caching.md => 13-01-01-Caching.md} | 0 ...de-Cache.md => 13-02-01-Bytecode-Cache.md} | 0 ...-Caching.md => 13-03-01-Object-Caching.md} | 0 ...-01-Resources.md => 14-01-01-Resources.md} | 0 ...1-Frameworks.md => 14-02-01-Frameworks.md} | 0 ...1-Components.md => 14-03-01-Components.md} | 0 .../{13-04-01-Books.md => 14-04-01-Books.md} | 0 ...-01-Community.md => 15-01-01-Community.md} | 0 ...{15-01-01-PHPDoc.md => 16-01-01-PHPDoc.md} | 0 35 files changed, 118 insertions(+), 2 deletions(-) rename _posts/{07-01-02-Interacting-via-Code.md => 07-02-01-Interacting-via-Code.md} (97%) rename _posts/{07-01-03-Abstraction-Layers.md => 07-03-01-Abstraction-Layers.md} (95%) create mode 100644 _posts/08-01-01-Templating.md create mode 100644 _posts/08-02-01-Benefits.md create mode 100644 _posts/08-03-01-Plain-PHP-Templates.md create mode 100644 _posts/08-04-01-Compiled-Templates.md create mode 100644 _posts/08-05-01-Further-Reading.md rename _posts/{08-01-01-Errors-and-Exceptions.md => 09-01-01-Errors-and-Exceptions.md} (100%) rename _posts/{08-02-01-Errors.md => 09-02-01-Errors.md} (100%) rename _posts/{08-03-01-Exceptions.md => 09-03-01-Exceptions.md} (100%) rename _posts/{09-01-01-Security.md => 10-01-01-Security.md} (100%) rename _posts/{09-02-01-Web-Application-Security.md => 10-02-01-Web-Application-Security.md} (100%) rename _posts/{09-03-01-Password-Hashing.md => 10-03-01-Password-Hashing.md} (100%) rename _posts/{09-04-01-Data-Filtering.md => 10-04-01-Data-Filtering.md} (100%) rename _posts/{09-05-01-Configuration-Files.md => 10-05-01-Configuration-Files.md} (100%) rename _posts/{09-06-01-Register-Globals.md => 10-06-01-Register-Globals.md} (100%) rename _posts/{09-07-01-Error-Reporting.md => 10-07-01-Error-Reporting.md} (100%) rename _posts/{10-01-01-Testing.md => 11-01-01-Testing.md} (100%) rename _posts/{10-02-01-Test-Driven-Development.md => 11-02-01-Test-Driven-Development.md} (100%) rename _posts/{10-03-01-Behavior-Driven-Development.md => 11-03-01-Behavior-Driven-Development.md} (100%) rename _posts/{10-04-01-Complementary-Testing-Tools.md => 11-04-01-Complementary-Testing-Tools.md} (100%) rename _posts/{11-01-01-Servers-and-Deployment.md => 12-01-01-Servers-and-Deployment.md} (100%) rename _posts/{11-02-01-Platform-as-a-Service.md => 12-02-01-Platform-as-a-Service.md} (100%) rename _posts/{11-03-01-Virtual-or-Dedicated-Servers.md => 12-03-01-Virtual-or-Dedicated-Servers.md} (100%) rename _posts/{11-04-01-Shared-Servers.md => 12-04-01-Shared-Servers.md} (100%) rename _posts/{11-05-01-Building-your-Application.md => 12-05-01-Building-your-Application.md} (100%) rename _posts/{12-01-01-Caching.md => 13-01-01-Caching.md} (100%) rename _posts/{12-02-01-Bytecode-Cache.md => 13-02-01-Bytecode-Cache.md} (100%) rename _posts/{12-03-01-Object-Caching.md => 13-03-01-Object-Caching.md} (100%) rename _posts/{13-01-01-Resources.md => 14-01-01-Resources.md} (100%) rename _posts/{13-02-01-Frameworks.md => 14-02-01-Frameworks.md} (100%) rename _posts/{13-03-01-Components.md => 14-03-01-Components.md} (100%) rename _posts/{13-04-01-Books.md => 14-04-01-Books.md} (100%) rename _posts/{14-01-01-Community.md => 15-01-01-Community.md} (100%) rename _posts/{15-01-01-PHPDoc.md => 16-01-01-PHPDoc.md} (100%) diff --git a/_posts/07-01-02-Interacting-via-Code.md b/_posts/07-02-01-Interacting-via-Code.md similarity index 97% rename from _posts/07-01-02-Interacting-via-Code.md rename to _posts/07-02-01-Interacting-via-Code.md index 9f38be9..c3364e4 100644 --- a/_posts/07-01-02-Interacting-via-Code.md +++ b/_posts/07-02-01-Interacting-via-Code.md @@ -4,7 +4,7 @@ title: Interacting with Databases anchor: databases_interacting --- -## Interacting with Databases +## Interacting with Databases {#databases_interacting_title} When developers first start to learn PHP, they often end up mixing their database interaction up with their presentation logic, using code that might look like this: diff --git a/_posts/07-01-03-Abstraction-Layers.md b/_posts/07-03-01-Abstraction-Layers.md similarity index 95% rename from _posts/07-01-03-Abstraction-Layers.md rename to _posts/07-03-01-Abstraction-Layers.md index f2bcfc4..ee61b63 100644 --- a/_posts/07-01-03-Abstraction-Layers.md +++ b/_posts/07-03-01-Abstraction-Layers.md @@ -4,7 +4,7 @@ title: Abstraction Layers anchor: databases_abstraction_layers --- -## Abstraction Layers +## Abstraction Layers {#databases_abstraction_layers_title} Many frameworks provide their own abstraction layer which may or may not sit on top of PDO. These will often emulate features for one database system that is missing from another by wrapping your queries in PHP methods, giving you actual database abstraction instead of just the connection abstraction that PDO provides. diff --git a/_posts/08-01-01-Templating.md b/_posts/08-01-01-Templating.md new file mode 100644 index 0000000..8957e2f --- /dev/null +++ b/_posts/08-01-01-Templating.md @@ -0,0 +1,12 @@ +--- +title: Templating +anchor: templating +--- + +# Templating {#templating_title} + +Templates provide a convenient way of separating your controller and domain logic from your presentation logic. +Templates typically contain the HTML of your application, but may also be used for other formats, such as XML. +Templates are often referred to as "views", the second component of the +[model–view–controller](http://www.phptherightway.com/pages/Design-Patterns.html#model-view-controller) (MVC) +software architecture pattern. \ No newline at end of file diff --git a/_posts/08-02-01-Benefits.md b/_posts/08-02-01-Benefits.md new file mode 100644 index 0000000..1da94d6 --- /dev/null +++ b/_posts/08-02-01-Benefits.md @@ -0,0 +1,21 @@ +--- +isChild: true +anchor: templating_benefits +--- + +## Benefits {#templating_benefits_title} + +The main benefit to using templates is the clear separation they create between the presentation logic and the rest of +your application. Templates have the sole responsibility of displaying formatted content. They are not responsible for +data lookup, persistence or other more complex tasks. This leads to cleaner, more readable code which is especially +helpful in a team environment where developers work on the server-side code (controllers, models) and designers work on +the client-side code (markup). + +Templates also improve the organization of presentation code. Templates are typically placed in a "views" folder, each +defined within a single file. This approach encourages code reuse where larger blocks of code are broken into smaller, +reusable pieces. For example, your site header and footer can each be defined as templates, which are then included +before and after each page template. + +Finally, depending on the library you use, templates can offer more security by automatically escaping user-generated +content. Some libraries even offer sand-boxing, where template designers are only given access to white-listed +variables and functions. \ No newline at end of file diff --git a/_posts/08-03-01-Plain-PHP-Templates.md b/_posts/08-03-01-Plain-PHP-Templates.md new file mode 100644 index 0000000..137d6e4 --- /dev/null +++ b/_posts/08-03-01-Plain-PHP-Templates.md @@ -0,0 +1,28 @@ +--- +isChild: true +anchor: plain_php_templates +--- + +## Plain PHP Templates {#plain_php_templates_title} + +Plain PHP templates are simply templates that use native PHP code. They are a natural choice since PHP is actually a +template language itself. That simply means that you can combine PHP code within other code, like HTML. This is +beneficial to PHP developers as there is no new syntax to learn, they know the functions available to them, and their +code editors already have PHP syntax highlighting and auto-completion built-in. Further, plain PHP templates tend to be +very fast as no compiling stage is required. + +Every modern PHP framework employs some kind of template system, most of which use plain PHP by default. Outside of +frameworks, libraries like [Plates](http://platesphp.com/) or [Aura.View](https://github.com/auraphp/Aura.View) make +working with plain PHP templates easier by offering modern template functionality such as inheritance, layouts and +extensions. + +Example of a plain PHP template (using the [Plates](http://platesphp.com/) library): + +{% highlight php %} +insert('header', ['title' => 'User Profile']) ?> + +

User Profile

+

Hello, escape($name)?>

+ +insert('footer') ?> +{% endhighlight %} \ No newline at end of file diff --git a/_posts/08-04-01-Compiled-Templates.md b/_posts/08-04-01-Compiled-Templates.md new file mode 100644 index 0000000..d46cd70 --- /dev/null +++ b/_posts/08-04-01-Compiled-Templates.md @@ -0,0 +1,28 @@ +--- +isChild: true +anchor: compiled_templates +--- + +## Compiled Templates {#compiled_templates} + +While PHP has evolved into a mature, object oriented language, it +[hasn't improved much](http://fabien.potencier.org/article/34/templating-engines-in-php) as a templating language. +Compiled templates, like [Twig](http://twig.sensiolabs.org/) or [Smarty](http://www.smarty.net/), fill this void by +offering a new syntax that has been geared specifically to templating. From automatic escaping, to inheritance and +simplified control structures, compiled templates are designed to be easier to write, cleaner to read and safer to use. +Compiled templates can even be shared across different languages, [Mustache](http://mustache.github.io/) being a good +example of this. Since these templates must be compiled there is a slight performance hit, however this is very minimal +when proper caching is used. + +Example of a compiled template (using the [Twig](http://twig.sensiolabs.org/) library): + +{% highlight text %} +{% raw %} +{% include 'header.html' with {'title': 'User Profile'} %} + +

User Profile

+

Hello, {{ name }}

+ +{% include 'footer.html' %} +{% endraw %} +{% endhighlight %} \ No newline at end of file diff --git a/_posts/08-05-01-Further-Reading.md b/_posts/08-05-01-Further-Reading.md new file mode 100644 index 0000000..fd8c160 --- /dev/null +++ b/_posts/08-05-01-Further-Reading.md @@ -0,0 +1,27 @@ +--- +isChild: true +anchor: templating_further_reading +--- + +## Further Reading {#templating_further_reading_title} + +### Articles & Tutorials + +- [Templating Engines in PHP](http://fabien.potencier.org/article/34/templating-engines-in-php) +- [An Introduction to Views & Templating in CodeIgniter](http://code.tutsplus.com/tutorials/an-introduction-to-views-templating-in-codeigniter--net-25648) +- [Getting Started With PHP Templating](http://www.smashingmagazine.com/2011/10/17/getting-started-with-php-templating/) +- [Roll Your Own Templating System in PHP](http://code.tutsplus.com/tutorials/roll-your-own-templating-system-in-php--net-16596) +- [Master Pages](https://laracasts.com/series/laravel-from-scratch/episodes/7) +- [Working With Templates in Symfony 2](http://code.tutsplus.com/tutorials/working-with-templates-in-symfony-2--cms-21172) + +### Libraries + +- [Aura.View](https://github.com/auraphp/Aura.View) *(native)* +- [Blade](http://laravel.com/docs/templates) *(compiled, framework specific)* +- [Dwoo](http://dwoo.org/) *(compiled)* +- [Mustache](https://github.com/bobthecow/mustache.php) *(compiled)* +- [PHPTAL](http://phptal.org/) *(compiled)* +- [Plates](http://platesphp.com/) *(native)* +- [Smarty](http://www.smarty.net/) *(compiled)* +- [Twig](http://twig.sensiolabs.org/) *(compiled)* +- [Zend\View](http://framework.zend.com/manual/2.3/en/modules/zend.view.quick-start.html) *(native, framework specific)* \ No newline at end of file diff --git a/_posts/08-01-01-Errors-and-Exceptions.md b/_posts/09-01-01-Errors-and-Exceptions.md similarity index 100% rename from _posts/08-01-01-Errors-and-Exceptions.md rename to _posts/09-01-01-Errors-and-Exceptions.md diff --git a/_posts/08-02-01-Errors.md b/_posts/09-02-01-Errors.md similarity index 100% rename from _posts/08-02-01-Errors.md rename to _posts/09-02-01-Errors.md diff --git a/_posts/08-03-01-Exceptions.md b/_posts/09-03-01-Exceptions.md similarity index 100% rename from _posts/08-03-01-Exceptions.md rename to _posts/09-03-01-Exceptions.md diff --git a/_posts/09-01-01-Security.md b/_posts/10-01-01-Security.md similarity index 100% rename from _posts/09-01-01-Security.md rename to _posts/10-01-01-Security.md diff --git a/_posts/09-02-01-Web-Application-Security.md b/_posts/10-02-01-Web-Application-Security.md similarity index 100% rename from _posts/09-02-01-Web-Application-Security.md rename to _posts/10-02-01-Web-Application-Security.md diff --git a/_posts/09-03-01-Password-Hashing.md b/_posts/10-03-01-Password-Hashing.md similarity index 100% rename from _posts/09-03-01-Password-Hashing.md rename to _posts/10-03-01-Password-Hashing.md diff --git a/_posts/09-04-01-Data-Filtering.md b/_posts/10-04-01-Data-Filtering.md similarity index 100% rename from _posts/09-04-01-Data-Filtering.md rename to _posts/10-04-01-Data-Filtering.md diff --git a/_posts/09-05-01-Configuration-Files.md b/_posts/10-05-01-Configuration-Files.md similarity index 100% rename from _posts/09-05-01-Configuration-Files.md rename to _posts/10-05-01-Configuration-Files.md diff --git a/_posts/09-06-01-Register-Globals.md b/_posts/10-06-01-Register-Globals.md similarity index 100% rename from _posts/09-06-01-Register-Globals.md rename to _posts/10-06-01-Register-Globals.md diff --git a/_posts/09-07-01-Error-Reporting.md b/_posts/10-07-01-Error-Reporting.md similarity index 100% rename from _posts/09-07-01-Error-Reporting.md rename to _posts/10-07-01-Error-Reporting.md diff --git a/_posts/10-01-01-Testing.md b/_posts/11-01-01-Testing.md similarity index 100% rename from _posts/10-01-01-Testing.md rename to _posts/11-01-01-Testing.md diff --git a/_posts/10-02-01-Test-Driven-Development.md b/_posts/11-02-01-Test-Driven-Development.md similarity index 100% rename from _posts/10-02-01-Test-Driven-Development.md rename to _posts/11-02-01-Test-Driven-Development.md diff --git a/_posts/10-03-01-Behavior-Driven-Development.md b/_posts/11-03-01-Behavior-Driven-Development.md similarity index 100% rename from _posts/10-03-01-Behavior-Driven-Development.md rename to _posts/11-03-01-Behavior-Driven-Development.md diff --git a/_posts/10-04-01-Complementary-Testing-Tools.md b/_posts/11-04-01-Complementary-Testing-Tools.md similarity index 100% rename from _posts/10-04-01-Complementary-Testing-Tools.md rename to _posts/11-04-01-Complementary-Testing-Tools.md diff --git a/_posts/11-01-01-Servers-and-Deployment.md b/_posts/12-01-01-Servers-and-Deployment.md similarity index 100% rename from _posts/11-01-01-Servers-and-Deployment.md rename to _posts/12-01-01-Servers-and-Deployment.md diff --git a/_posts/11-02-01-Platform-as-a-Service.md b/_posts/12-02-01-Platform-as-a-Service.md similarity index 100% rename from _posts/11-02-01-Platform-as-a-Service.md rename to _posts/12-02-01-Platform-as-a-Service.md diff --git a/_posts/11-03-01-Virtual-or-Dedicated-Servers.md b/_posts/12-03-01-Virtual-or-Dedicated-Servers.md similarity index 100% rename from _posts/11-03-01-Virtual-or-Dedicated-Servers.md rename to _posts/12-03-01-Virtual-or-Dedicated-Servers.md diff --git a/_posts/11-04-01-Shared-Servers.md b/_posts/12-04-01-Shared-Servers.md similarity index 100% rename from _posts/11-04-01-Shared-Servers.md rename to _posts/12-04-01-Shared-Servers.md diff --git a/_posts/11-05-01-Building-your-Application.md b/_posts/12-05-01-Building-your-Application.md similarity index 100% rename from _posts/11-05-01-Building-your-Application.md rename to _posts/12-05-01-Building-your-Application.md diff --git a/_posts/12-01-01-Caching.md b/_posts/13-01-01-Caching.md similarity index 100% rename from _posts/12-01-01-Caching.md rename to _posts/13-01-01-Caching.md diff --git a/_posts/12-02-01-Bytecode-Cache.md b/_posts/13-02-01-Bytecode-Cache.md similarity index 100% rename from _posts/12-02-01-Bytecode-Cache.md rename to _posts/13-02-01-Bytecode-Cache.md diff --git a/_posts/12-03-01-Object-Caching.md b/_posts/13-03-01-Object-Caching.md similarity index 100% rename from _posts/12-03-01-Object-Caching.md rename to _posts/13-03-01-Object-Caching.md diff --git a/_posts/13-01-01-Resources.md b/_posts/14-01-01-Resources.md similarity index 100% rename from _posts/13-01-01-Resources.md rename to _posts/14-01-01-Resources.md diff --git a/_posts/13-02-01-Frameworks.md b/_posts/14-02-01-Frameworks.md similarity index 100% rename from _posts/13-02-01-Frameworks.md rename to _posts/14-02-01-Frameworks.md diff --git a/_posts/13-03-01-Components.md b/_posts/14-03-01-Components.md similarity index 100% rename from _posts/13-03-01-Components.md rename to _posts/14-03-01-Components.md diff --git a/_posts/13-04-01-Books.md b/_posts/14-04-01-Books.md similarity index 100% rename from _posts/13-04-01-Books.md rename to _posts/14-04-01-Books.md diff --git a/_posts/14-01-01-Community.md b/_posts/15-01-01-Community.md similarity index 100% rename from _posts/14-01-01-Community.md rename to _posts/15-01-01-Community.md diff --git a/_posts/15-01-01-PHPDoc.md b/_posts/16-01-01-PHPDoc.md similarity index 100% rename from _posts/15-01-01-PHPDoc.md rename to _posts/16-01-01-PHPDoc.md