$30 off During Our Annual Pro Sale. View Details »

Zend Framework Overview (Atlanta PHP May 2006)

Zend Framework Overview (Atlanta PHP May 2006)

For nearly two months, the Zend Framework has been the great talk of the PHP community. Just one day following Atlanta PHP's March meeting, the Zend Framework preview release was announced, and folks have been eager to download, play with it, and provide their feedback. At our May meeting, Ben Ramsey will take the Zend Framework for a test drive, outlining its current state, the direction it's heading, and rounding out the presentation with a quick tutorial on using the framework (code samples included). Finally, we'll start work on our group project, using the Zend Framework as a basis.

Ben Ramsey
PRO

May 04, 2006
Tweet

More Decks by Ben Ramsey

Other Decks in Programming

Transcript

  1. Zend Framework Overview
    Ben Ramsey
    Atlanta PHP
    May 4, 2006

    View Slide

  2. Who am I to discuss Zend?
    • I’m Ben Ramsey, and I have a blog
    • Professional PHP programmer for 5 years
    • Author of articles on PHP in International PHP
    Magazine and php|architect
    • Founding Principal of the PHP Security
    Consortium
    • PHP enthusiast and advocate

    View Slide

  3. What we will learn today
    • Zend Framework background
    • Framework components overview
    • Zend Framework roadmap
    • Setting up your environment
    • A “hello, world” example

    View Slide

  4. Zend Framework background

    View Slide

  5. What is the Zend
    Framework?
    • “Zend Framework is a high quality and open
    source framework for developing Web
    Applications and Web Services.”
    • Zend’s answer to Enterprise-grade frameworks
    • Zend’s tool to promote PHP use in the
    Enterprise

    View Slide

  6. What is the Zend
    Framework?
    • Like PEAR, it is a collection of classes that
    may be used together or separately
    • Designed to be free from Intellectual Property
    disagreements

    View Slide

  7. Project goals
    • Provide a repository of high quality
    components that are actively supported
    • Provide a complete system for developing web
    applications powered by PHP 5
    • Don’t change PHP -- it’s already a great
    platform (even without a framework!)

    View Slide

  8. Project goals
    • Embrace collaboration and community to
    further advance PHP 5 programming
    • Positively contribute to the PHP 5 ecosystem
    and the PHP Collaboration Project

    View Slide

  9. PHP Collaboration Project
    • a solid framework/development environment
    • enriched development tools (Eclipse)
    • best practices

    View Slide

  10. Zend Framework License
    • BSD license (was originally similar to the PHP
    license with the “advertising clause”)
    • Located here:
    http://framework.zend.com/license/

    View Slide

  11. More background
    • There is a contribution/proposal process
    • All contributors must sign the Contributor
    License Agreement
    • There are rigid standards for writing code
    • The framework is fairly easy to use

    View Slide

  12. Framework components
    overview
    Zend_Controller
    Zend_Db
    Zend_Feed
    Zend_Filter
    Zend_InputFilter
    Zend_HttpClient
    Zend_Json
    Zend_Log
    Zend_Mail
    Zend_Mime
    Zend_Pdf
    Zend_Search
    Zend_Service_Amazon
    Zend_Service_Flickr
    Zend_Service_Rest
    Zend_Service_Yahoo
    Zend_View
    Zend_XmlRpc

    View Slide

  13. Zend Framework roadmap
    • Currently seeking contributions: Zend_Auth,
    Zend_Acl, Zend_Feed_Builder, Zend_File,
    Zend_Http_Server, Zend_Locale,
    Zend_Session
    • Stable release by Fall 2006?
    • More info:
    http://framework.zend.com/roadmap/

    View Slide

  14. Setting up your environment

    View Slide

  15. Requirements
    • PHP 5.0.4 with PDO extensions required;
    PHP 5.1 recommended
    • Apache HTTPD server recommended for
    mod_rewrite rules, but not required
    • Download from:
    http://framework.zend.com/download

    View Slide

  16. Set up your app structure
    • I recommend the following structure:
    /
    application/
    controllers/
    views/
    library/
    Zend/

    www/
    images/
    styles/
    .htaccess
    index.php

    View Slide

  17. Server configuration
    • Create an .htaccess file with the following and
    place in www/
    php_value include_path “../library”
    RewriteEngine on
    RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php

    View Slide

  18. Bootstrap file
    /* this file lives at www/index.php */
    include 'Zend.php';
    function __autoload($class)
    {
    Zend::loadClass($class);
    }
    $view = new Zend_View;
    $view->addScriptPath('../application/views');
    Zend::register('view', $view);
    $controller = Zend_Controller_Front::getInstance()
    ->setControllerDirectory('../application/controllers')
    ->dispatch();
    ?>

    View Slide

  19. A “hello, world” example

    View Slide

  20. Application structure
    • Zend Framework applications are controlled by
    instructions from the URI
    • Thus, consider the following:
    /
    /view/#
    /post/edit
    /post/save
    /post/remove/id/#

    View Slide

  21. Create our controller
    • The framework dispatcher calls the index
    controller when someone access the root of the
    site (/), so we need to create one to handle
    these requests
    • Create IndexController.php in
    application/contorllers/

    View Slide

  22. IndexController.php
    class IndexController extends Zend_Controller_Action
    {
    public function indexAction()
    {
    $view = Zend::registry('view');
    $view->title = 'Hiya';
    $view->body = 'Hello, World!';
    echo $view->render('hello.php');
    }
    public function noRouteAction()
    {
    $this->_redirect('/');
    }
    }
    ?>

    View Slide

  23. Create our view
    • Create the following file (hello.php) and
    store in application/views/


    escape($this->title); ?>


    escape($this->body); ?>


    View Slide

  24. Say “hello” to everyone
    • Now, when a user accesses http://example.org/
    or http://example.org/index, they’ll see the
    following:


    Hiya


    Hello, World!


    View Slide

  25. What have we learned?
    • background on the framework
    • overview of components
    • quick look at the roadmap
    • how to set up your environment
    • said “hello” to the world

    View Slide

  26. For more information
    • Zend Framework: http://framework.zend.com/
    • Zend Developer Zone: http://devzone.zend.com/
    • Integrate Propel: http://devzone.zend.com/node/view/id/184
    • Integrate Smarty: http://devzone.zend.com/node/view/id/156
    • php|arch April 06: http://phparch.com/issue.php?mid=79
    • Chris Shiflett’s tutorial: http://phparch/zftut
    • My blog: http://benramsey.com

    View Slide