• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Introduction to Zend Framework
 

Introduction to Zend Framework

on

  • 1,667 views

A quick introduction to same aspects of the Zend Framework, including installation and setup using Zend_Tool, ZF's MVC architecture, database models, controllers, view scripts, layouts and forms. ...

A quick introduction to same aspects of the Zend Framework, including installation and setup using Zend_Tool, ZF's MVC architecture, database models, controllers, view scripts, layouts and forms. Delivered at the April meeting of phpNE.

Statistics

Views

Total Views
1,667
Views on SlideShare
1,667
Embed Views
0

Actions

Likes
1
Downloads
21
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Introduction to Zend Framework Introduction to Zend Framework Presentation Transcript

    • An Introduction to Zend Framework
      • Jamie Hurst
    • Who is this guy?
      • PHP slave at LINGsCARS.com
      • Occasional freelancer
      • Blogger
      • Geekest drink frequenter
      • @JamieFDHurst
    • Getting the Framework http://framework.zend.com / * you will need to register!
    • Installation Copy your downloaded directory somewhere handy... Add this include path into your php.ini file...
    • Installation Make sure your PATH variable references your bin directory... This allows you to make use of the Zend_Tool command line interface
    • New Project zf.sh create project <myproject> Controllers Models Views
    • New Project If your web server is setup correctly, you should see this! Application is accessed from the public folder
    • A Quick Zend Overview
      • Models (db-tables, object models)
      • Views (helpers, scripts, layouts)
      • Controllers (actions, helpers)
      • Forms
      • Modules
    • Some Basics
      • All classes named for their folder (e.g. Application_Model_Post in application/models/post.php)
      • Every Zend module is autoloaded when needed
      • Default controller/action is Index
      • URL format: /<controller>/<action>
    • Database
      • post
      • id
      • category_id
      • title
      • content
      • time
      • category
      • id
      • name
      • comment
      • id
      • post_id
      • author
      • content
      • time
      1 * 1 * Edit your application/configs/application.ini file...
    • Tables and Rows Create a table and row model for each table Table classes fetch and find rows, and perform searches... Row objects handle accessing, updating and deleting the data zf.sh create db-table <name> <table-name> zf.sh create model <name>
    • Database Models Table classes should specify the $_rowClass property Row classes should extend Zend_Db_Table_Row_Abstract Table classes should extend Zend_Db_Table_Abstract
    • Controllers Controllers have many actions, and an init() method Action methods end in “Action”
    • Controllers Each action has a corresponding view script Variables and helpers can be accessed
    • Displaying Posts Access the posts table and row models and pass the results to the view The fetchall() method allows you to query “ where”s and “ order by”s
    • Displaying Posts The view script accesses variables passed by the controller Note the clever url helper!
    • The Result... Ta-da! Posts displaying on your index page! But there’s something missing...
    • What about Categories and Comments? The post model needs to be modified to get these properties using the other model objects Here is the getCategory method in the Post model, making use of the find method
    • Categories and Comments A custom table method is used... Which uses the where functionality
    • Categories and Comments And now, with some simple alterations to the view script... The beauty of chaining these objects together...
    • Categories and Comments The result shows the categories and count of comments!
    • Layouts Zend provides layouts, which can be used to wrap the entire view in a consistent script Edit your application.ini file to enable them...
    • Layouts Build your layout script with space for each view script’s content, and put it in the application/layouts/scripts/ folder This is where the view script is inserted
    • Layouts And the result of the layout wrapping:
    • Actions An action for viewing individual posts would be helpful... zf.sh create action <action> <controller> A blank action is created...
    • Individual Posts We’ll need a parameter to know which post to display... This is also a chance to use some conditional statements in the view script... We passed this parameter in the earlier url helper
    • Individual Posts Now to build a quick view script for the action...
    • Individual Posts Now let’s make a quick comment form...
    • Zend_Form
      • Full extensible support for all HTML elements
      • Easy transition to ajax forms using jQuery or other
      • Validation
      • Decorators
      • Customisation
    • Creating the Form zf.sh create form <name> Simply add the elements in the init method
    • Including the Form And the form to the controller and handle when it is submitted Validation is handled very easily in one line of code
    • Including the Form Simply echoing the form variable displays all the elements and any errors
    • Completed Form The labels and elements are all rendered correctly using their default decorators Labels and elements wrapped in <dt>s and <dd>s
    • Creating an RSS Feed Now the Index action will support XML output too, with no extra changes to the action at all! To access different context types, use the format parameter in your GET query string, e.g. /index/index/format/xml
    • Creating an RSS Feed The view script for this context is views/scripts/index/index.xml.phtml
    • RSS Feed And there is our finished feed!
    • Quick Summary
      • Setting up your project - Zend_Tool
      • Database configuration & models
      • Controllers & actions
      • View scripts
      • Forms
      • MVC context-switching
    • Thank you!
      • Feel free to send any Zend-related questions to [email_address] ,
      • or tweet me @JamieFDHurst .