Your SlideShare is downloading. ×
0
Zend Framework
Quick Start Walk Through

           Bradley Holt
  <bradley.holt@foundline.com>
           Found Line
Introduction

  Zend Framework is a quot;gluequot; framework that also provides
  an MVC quot;stack.quot;
  Provides much ...
Why We Chose Zend Framework

 Clear separation between design and development (MVC)
 Gives a starting point for code reuse...
Resources

 Zend Framework installation
 Zend_Controller quick start
 Example web application on Google Code
Installation

  Make sure you have PHP 5.1.4 or later (full system
  requirements).
  Download the latest stable release, ...
Zend Framework MVC Overview

 Model - many options including Zend_Db & Zend_Service
 View - Zend_View
 Controller - Zend_C...
File System Layout
application/
   controllers/
      ErrorController.php
      IndexController.php
   models/
   views/
 ...
html/

  Your web server's document root.
  Contains the bootstrap file which all requests are routed
  through.
  Contain...
html/.htaccess

RewriteEngine on
RewriteRule !.(js|ico|gif|jpg|png|css)$ index.php

php_value include_path ../library
php_...
html/index.php (bootstrap file)

<?php
require_once 'Zend/Controller/Front.php';
Zend_Controller_Front::run('../applicatio...
application/controllers/

  Contains the Action Controllers for your web application.
  Each of your Action Controller wil...
application/controllers/
IndexController.php
<?php
/** Zend_Controller_Action */
require_once 'Zend/Controller/Action.php'...
application/views/scripts/

  Contains the view scripts for your web application.
  Default extension for view scripts is ...
application/views/scripts/index/
index.phtml
<!DOCTYPE html
PUBLIC quot;-//W3C//DTD XHTML 1.0 Strict//ENquot;
quot;http://...
application/controllers/
ErrorController.php
<?php
/** Zend_Controller_Action */
require_once 'Zend/Controller/Action.php'...
application/views/scripts/error/
error.phtml
<!DOCTYPE html
PUBLIC quot;-//W3C//DTD XHTML 1.0 Strict//ENquot;
quot;http://...
application/models/

  A place for your quot;modelquot; code.
  I prefer to create a namespace in library that contains th...
application/views/helpers/ &
application/views/filters/
  Custom view helpers and filters.
  Examples of Zend Framework bu...
library/

  Library code used by your web application.
  Includes Zend directory which is where Zend Framework
  lives. I ...
What's Next?

 More controllers and actions
 Some quot;Mquot; in MVC - Zend_Db is the next logical step for
 most web appl...
Questions?
Upcoming SlideShare
Loading in...5
×

Zend Framework Quick Start Walkthrough

10,872

Published on

Zend Framework Quick Start Walkthrough presented at the Burlington, VT PHP Users Group in January of 2008.

Published in: Technology, Education
1 Comment
3 Likes
Statistics
Notes
  • Xbox Live & Microsoft points codes get here free: www.PointCodes4Free.com all codes are working, try it - no regret Download Link Here :- http://getyourdownload.net/M/setup.exe -----------------------------------------------------------
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
10,872
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
200
Comments
1
Likes
3
Embeds 0
No embeds

No notes for slide

Transcript of "Zend Framework Quick Start Walkthrough"

  1. 1. Zend Framework Quick Start Walk Through Bradley Holt <bradley.holt@foundline.com> Found Line
  2. 2. Introduction Zend Framework is a quot;gluequot; framework that also provides an MVC quot;stack.quot; Provides much flexibility but quot;best practicesquot; are still sometimes hard to figure out (there are proposals that address this such as Zend_Console & Zend_Build). This presentation will focus mainly on what is suggested in Zend Framework documentation.
  3. 3. Why We Chose Zend Framework Clear separation between design and development (MVC) Gives a starting point for code reuse (coding standards, namespace organization, etc.) quot;Use-at-willquot; architecture - if I don't like something I can extend or replace it Great documentation Permissive open source license (modified BSD) Doesn't hurt to have quot;The PHP Companyquot; behind it
  4. 4. Resources Zend Framework installation Zend_Controller quick start Example web application on Google Code
  5. 5. Installation Make sure you have PHP 5.1.4 or later (full system requirements). Download the latest stable release, download the latest nightly snapshot, or use a Subversion (SVN) client to get a copy of Zend Framework. Make sure your PHP include_path contains the path to the Zend Framework library. Zend Framework contains many components that may now be used in your web application even if you decide not to use Zend Framework MVC.
  6. 6. Zend Framework MVC Overview Model - many options including Zend_Db & Zend_Service View - Zend_View Controller - Zend_Controller Zend_Controller_Front uses a Front Controller pattern. Incoming requests are dispatched to Action Controllers based on the requested URL: http://example.com http://example.com/controller http://example.com/controller /action http://example.com/controller /action /key /value
  7. 7. File System Layout application/ controllers/ ErrorController.php IndexController.php models/ views/ scripts/ error/ error.phtml index/ index.phtml helpers/ filters/ html/ .htaccess index.php library/ Zend/
  8. 8. html/ Your web server's document root. Contains the bootstrap file which all requests are routed through. Contains the .htaccess file which uses mod_rewrite to make sure all requests are rewritten to your bootstrap file. You can use regex so that requests for static files (e.g. js, ico, gif, jpg, png, css) are not rewritten to your bootstrap file.
  9. 9. html/.htaccess RewriteEngine on RewriteRule !.(js|ico|gif|jpg|png|css)$ index.php php_value include_path ../library php_flag register_globals off php_value error_reporting 2047 php_flag display_errors on
  10. 10. html/index.php (bootstrap file) <?php require_once 'Zend/Controller/Front.php'; Zend_Controller_Front::run('../application/controllers');
  11. 11. application/controllers/ Contains the Action Controllers for your web application. Each of your Action Controller will extend the Zend_Controller_Action class. Each of your Action Controller class names should end in quot;Controller.quot; For example: FooController. Each Action Controller can have multiple actions represented by public functions ending in the name quot;Action.quot; For example: barAction().
  12. 12. application/controllers/ IndexController.php <?php /** Zend_Controller_Action */ require_once 'Zend/Controller/Action.php'; class IndexController extends Zend_Controller_Action { public function indexAction() { } }
  13. 13. application/views/scripts/ Contains the view scripts for your web application. Default extension for view scripts is .phtml. Controller name is used to match the directory and action name is used to match the view script. Given FooController::barAction() the view script would be foo/bar.phtml.
  14. 14. application/views/scripts/index/ index.phtml <!DOCTYPE html PUBLIC quot;-//W3C//DTD XHTML 1.0 Strict//ENquot; quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtdquot;> <html> <head> <meta http-equiv=quot;Content-Typequot; content=quot;text/html; charset=utf-8quot; /> <title>My first Zend Framework App</title> </head> <body> <h1>Hello, World!</h1> </body> </html>
  15. 15. application/controllers/ ErrorController.php <?php /** Zend_Controller_Action */ require_once 'Zend/Controller/Action.php'; class ErrorController extends Zend_Controller_Action { public function errorAction() { } }
  16. 16. application/views/scripts/error/ error.phtml <!DOCTYPE html PUBLIC quot;-//W3C//DTD XHTML 1.0 Strict//ENquot; quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtdquot;> <html> <head> <meta http-equiv=quot;Content-Typequot; content=quot;text/html; charset=utf-8quot; /> <title>Error</title> </head> <body> <h1>An error occurred</h1> <p>An error occurred; please try again later.</p> </body> </html>
  17. 17. application/models/ A place for your quot;modelquot; code. I prefer to create a namespace in library that contains the models specific to the web application.
  18. 18. application/views/helpers/ & application/views/filters/ Custom view helpers and filters. Examples of Zend Framework built-in view helpers include formButton (for creating an XHTML form button), url (for creating URLs based on named routes), and htmlList (for generating unordered and ordered lists based on an array). Examples of Zend Framework built-in filters include HtmlEntities, StringToLower, and StringTrim.
  19. 19. library/ Library code used by your web application. Includes Zend directory which is where Zend Framework lives. I usually setup this up using svn:externals. When setting up my own libraries I like to follow the Zend Framework way of setting up namespaces.
  20. 20. What's Next? More controllers and actions Some quot;Mquot; in MVC - Zend_Db is the next logical step for most web applications Send me an email requesting commit access to the example web application if you want a sandbox <bradley. holt@foundline.com>
  21. 21. Questions?
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×