Latest Version: 0.9.6.2
  Dashboard > Pylons Cookbook > ... > Getting Started > Pylons for PHP Users
  Pylons Cookbook Log In | Sign Up   View a printable version of the current page.  
  Pylons for PHP Users
Added by Mike Orr, last edited by James Gardner on Mar 19, 2007  (view change)
Labels: 
(None)

Name Space Page Section Version Status Reviewed Author(s)
Pylons for PHP Users Pylons CookBook Pylons for PHP Users Home 1.0 Draft False Mike Orr

This page tries to explain Pylons in terms familar to PHP users, and describes the specific differences between PHP and Pylons. Or at least it will when it's finished.

 High-level overview

 A web framework at its core has one basic responsibility: produce an HTML page with HTTP headers according to the URL requested.  Different frameworks do this in different ways:

  • Apache has a simple dispatcher that maps a URL to a file in a directory, and sends that file.
  • PHP is file-based.  It relies on Apache's dispatcher to find a specific .php file, and then "executes" it to produce the HTML.
  • Pylons handles the dispatching all on its own, via Routes (a Python library). Apache forwards the request to a running Pylons application.  Pylons uses Routes to determine which method to call in which controller class, based on the URL.  This method returns an HTML page as a string.  Pylons adds the HTTP headers and forwards the result to Apache.

A template is like a form letter.  "Dear Mr ___ : I am an accountant at __ Bank in Nigeria.  The __ of __ was killed in a politically-motivated assasination and left behind $ __ in an untraceable account.  I need your help to get this money out of the country away from corrupt ___ officials."  A template engine fills in the blanks and produces a finished document.  Mako, Genshi, Cheetah, and others are widely-used template engines in Pylons applications.  PHP applications frequently use Smarty templates for the same purpose.

A key difference is that in PHP your code is embedded in the HTML page, whereas in Pylons your code produces your HTML.  It can do that by returning a string, but most often it will invoke a template to produce the string.

Static (non-changing) files like images and stylesheets may be served directly by Apache outside Pylons, or by placing those files in a special "public" directory in your Pylons application.


Site running on a free Atlassian Confluence Open Source Project License granted to Pylons. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.3.3 Build:#645 Feb 13, 2007) - Bug/feature request - Contact Administrators
Top