SlideShare ist ein Scribd-Unternehmen logo
1 von 46
Downloaden Sie, um offline zu lesen
Zend Framework
  Introduction
 Features and Common Patterns
Examples from a demo blogging application named Postr are
used throughout this presentation. You can view, download, or
fork the demo web application on GitHub:

http://github.com/bradley-holt/postr
Zend_Tool
Automated scaffolding of project and project components

Used in creating the demo application, Postr

Referenced throughout this presentation
Zend_Tool
Create a Project
mkdir postr
cd postr
zf create project .
Zend_Tool
Project Structure
.zfproject.xml
application/
    Bootstrap.php
    configs/
        application.ini
    controllers/
        ErrorController.php
        IndexController.php
    views/
        scripts/
             error/
                 error.phtml
             index/
                 index.phtml
public/
    .htaccess
    index.php
tests/
    application/
        bootstrap.php
    library/
        bootstrap.php
    phpunit.xml
Front Controller
All HTTP requests for the application go through
one script.
Apache’s rewrite module (or equivalent) makes this
happen.




See:
Front Controller pattern
public/index.php
public/.htaccess
Zend_Application
Bootstraps the application

Provides reusable resources

Sets up PHP environment




See:
Zend_Application
application/Bootstrap.php
Con guration
Default con guration is in application/configs/application.ini

Allows for con guration sections; for example:
  • production
  • staging
  • testing
  • development
Sections can inherit from other sections


See:
application/con gs/application.ini
Name the Project
Default application class name pre x is Application_.
zf change application.class-name-prefix Postr_
Updated Con guration
Added to application/configs/application.ini:
[production]
appnamespace = "Postr_"




See:
application/con gs/application.ini
Model-View-Controller (MVC)
Composite of several design patterns
Isolates domain logic from input and presentation
Model: domain logic
View: presentation layer
Controller: interprets input and passes it to the
Model; provides Model data to the View

See:
Model-view-controller
application/models/
application/views/
application/controllers/
Zend_Layout
Implementation of the Two Step View pattern

Allows for consistent layout across multiple pages

Easier to manage than “includes”




See:
Zend_Layout
Two Step View
Zend_Layout
Enable Layout
zf enable layout
Zend_Layout
Layout View Script
application/
    layouts/
        scripts/
             layout.phtml


Added to application/configs/application.ini:
[production]
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"




See:
application/layouts/scripts/layout.phtml
application/con gs/application.ini
Controllers
Connects the Model and the View

Contains one or more actions

URL based routing typically decides what controller
and action to execute:
:controller/:action


Custom routing options available
View Scripts
PHP templates

No domain logic please!

Default suffix of .phtml

One view script per controller action (by default)
Create a Controller
zf create controller Entry
Entry Controller
and View Script
application/
    controllers/
        EntryController.php
    views/
        scripts/
             entry/
                 index.phtml
tests/
    application/
        controllers/
             EntryControllerTest.php




See:
application/controllers/EntryController.php
application/views/scripts/entry/index.phtml
tests/application/controllers/EntryControllerTest.php
Create Additional
Controller Actions
zf   create   action   new Entry
zf   create   action   get Entry
zf   create   action   edit Entry
zf   create   action   post Entry
zf   create   action   put Entry
zf   create   action   delete Entry
Entry Actions
Methods added to application/controllers/EntryController.php:
newAction()
getAction()
editAction()
postAction()
putAction()
deleteAction()




See:
application/controllers/EntryController.php
Entry Actions
View scripts created:
application/
    views/
        scripts/
             entry/
                 delete.phtml
                 edit.phtml
                 get.phtml
                 new.phtml
                 post.phtml
                 put.phtml




See:
application/views/scripts/entry/
Zend_Test
Functional (end-to-end) testing of controllers

Simulates HTTP requests to the application

No web server required

Also provides a DB testing facility




See:
Zend_Test
Functional Test
tests/application/controllers/EntryControllerTest.php
Models
Models are speci c to your domain
No such thing as one-size- ts all models
No Zend_Model
However, some useful patterns have emerged
Create a Model
zf create model Entry
Entry Model
application/
    models/
        Entry.php




See:
application/models/Entry.php
Zend_Form
Input ltering

Input validation

Form and element rendering

Huge time saver




See:
Zend_Form
Zend_Filter
Zend_Validate
Zend_Form
Create a Form
zf create form Entry
Zend_Form
Entry Form
application/
    forms/
        Entry.php




See:
application/forms/Entry.php
Zend_Db_Table
Object-oriented database interface

Implements the Table Data Gateway
and Row Data Gateway patterns




See:
Table Data Gateway
Row Data Gateway
Con gure a DB Adapter
zf   configure   dbadapter   "adapter=Pdo_Sqlite&dbname=../data/db/production.db"
zf   configure   dbadapter   "adapter=Pdo_Sqlite&dbname=../data/db/staging.db" -s staging
zf   configure   dbadapter   "adapter=Pdo_Sqlite&dbname=../data/db/testing.db" -s testing
zf   configure   dbadapter   "adapter=Pdo_Sqlite&dbname=../data/db/development.db" -s development
Updated Con guration
Added to application/configs/application.ini:
[production]
resources.db.adapter = "Pdo_Sqlite"
resources.db.params.dbname = APPLICATION_PATH "/../data/db/production.db"

[staging : production]
resources.db.adapter = "Pdo_Sqlite"
resources.db.params.dbname = APPLICATION_PATH "/../data/db/staging.db"

[testing : production]
resources.db.adapter = "Pdo_Sqlite"
resources.db.params.dbname = APPLICATION_PATH "/../data/db/testing.db"

[development : production]
resources.db.adapter = "Pdo_Sqlite"
resources.db.params.dbname = APPLICATION_PATH "/../data/db/development.db"




See:
application/con gs/application.ini
Load DB Schema
Project-speci c and not built-in to Zend Framework:
mkdir -p data/db
php scripts/load.sqlite.php




See:
scripts/load.sqlite.php
scripts/schema.sqlite.sql
Create DB Tables from
the Database
zf create dbtable.from-database
Entry and Entry Tag
DB Tables
application/
    models/
        DbTable/
             Entry.php
             EntryTag.php




See:
application/models/DbTable/Entry.php
application/models/DbTable/EntryTag.php
Data Mapper
Keeps your domain logic isolated from your
database implementation
Domain objects should not directly use data
mappers




See:
Data Mapper
Create a Data Mapper
zf create model EntryMapper
Entry Mapper
application/
    models/
        EntryMapper.php




See:
application/models/EntryMapper.php
Zend_Paginator
Pagination for database or any arbitrary data

Several adapters available:
   •   Array
   •   DbSelect
   •   DbTableSelect
   •   Iterator
   •   Null

   •   Write your own in order to paginate domain objects




See:
Zend_Paginator
Zend_Paginator
Create a Paginator Adapter
zf create model EntryPaginatorAdapter
Zend_Paginator
Entry Paginator Adapter
application/
    models/
        EntryPaginatorAdapter.php




See:
application/models/EntryPaginatorAdapter.php
Zend_Date
Manipulate dates and times

Useful for date and time calculations

Allows for input from and output to various formats

Used as a domain object in the Postr demo application:
  • Entry Updated
  • Entry Published

See:
Zend_Date
application/models/Entry.php
Zend_Markup
Renders BBcode or Textile markup into HTML or other formats

Extensible so may see other markup languages in the future

Used in the Postr demo application:
  • Entry Content and Entry Summary are stored as Textile
    markup
  • Entry Content and Entry Summary can optionally be
    retrieved as HTML

See:
Zend_Markup
BBCode
Textile
application/models/Entry.php
Zend_Navigation
Create menus, breadcrumbs, links, and sitemaps

Used to create the menu navigation in the Postr demo
application




See:
Zend_Navigation
application/Bootstrap.php
application/layouts/scripts/header.phtml
Controller Plugins
Allows developers to hook into various events during the
controller process:
   •   routeStartup()
   •   dispatchLoopStartup()
   •   preDispatch()
   •   postDispatch()
   •   dispatchLoopShutdown()
   •   routeShutdown()




See:
Controller Plugins
application/plugins/RouteContext.php
References
Bradley Holt’s demo application: Postr

Zend Framework Quick Start

Matthew Weier O’Phinney’s demo application: Pastebin

Zend Framework Programmer’s Reference Guide
Credits
Author
Bradley Holt


Layout & Design
Jason Pelletier




           This presentation licensed under
           Creative Commons—Attribution 3.0 United States License.

Weitere ähnliche Inhalte

Mehr von Bradley Holt

jQuery Conference Boston 2011 CouchApps
jQuery Conference Boston 2011 CouchAppsjQuery Conference Boston 2011 CouchApps
jQuery Conference Boston 2011 CouchAppsBradley Holt
 
OSCON 2011 CouchApps
OSCON 2011 CouchAppsOSCON 2011 CouchApps
OSCON 2011 CouchAppsBradley Holt
 
OSCON 2011 Learning CouchDB
OSCON 2011 Learning CouchDBOSCON 2011 Learning CouchDB
OSCON 2011 Learning CouchDBBradley Holt
 
Load Balancing with Apache
Load Balancing with ApacheLoad Balancing with Apache
Load Balancing with ApacheBradley Holt
 
CouchDB at New York PHP
CouchDB at New York PHPCouchDB at New York PHP
CouchDB at New York PHPBradley Holt
 
New Features in PHP 5.3
New Features in PHP 5.3New Features in PHP 5.3
New Features in PHP 5.3Bradley Holt
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHPBradley Holt
 
Resource-Oriented Web Services
Resource-Oriented Web ServicesResource-Oriented Web Services
Resource-Oriented Web ServicesBradley Holt
 
Zend Framework Quick Start Walkthrough
Zend Framework Quick Start WalkthroughZend Framework Quick Start Walkthrough
Zend Framework Quick Start WalkthroughBradley Holt
 
Burlington, VT PHP Users Group Subversion Presentation
Burlington, VT PHP Users Group Subversion PresentationBurlington, VT PHP Users Group Subversion Presentation
Burlington, VT PHP Users Group Subversion PresentationBradley Holt
 

Mehr von Bradley Holt (11)

jQuery Conference Boston 2011 CouchApps
jQuery Conference Boston 2011 CouchAppsjQuery Conference Boston 2011 CouchApps
jQuery Conference Boston 2011 CouchApps
 
OSCON 2011 CouchApps
OSCON 2011 CouchAppsOSCON 2011 CouchApps
OSCON 2011 CouchApps
 
OSCON 2011 Learning CouchDB
OSCON 2011 Learning CouchDBOSCON 2011 Learning CouchDB
OSCON 2011 Learning CouchDB
 
Load Balancing with Apache
Load Balancing with ApacheLoad Balancing with Apache
Load Balancing with Apache
 
CouchDB at New York PHP
CouchDB at New York PHPCouchDB at New York PHP
CouchDB at New York PHP
 
Intermediate PHP
Intermediate PHPIntermediate PHP
Intermediate PHP
 
New Features in PHP 5.3
New Features in PHP 5.3New Features in PHP 5.3
New Features in PHP 5.3
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Resource-Oriented Web Services
Resource-Oriented Web ServicesResource-Oriented Web Services
Resource-Oriented Web Services
 
Zend Framework Quick Start Walkthrough
Zend Framework Quick Start WalkthroughZend Framework Quick Start Walkthrough
Zend Framework Quick Start Walkthrough
 
Burlington, VT PHP Users Group Subversion Presentation
Burlington, VT PHP Users Group Subversion PresentationBurlington, VT PHP Users Group Subversion Presentation
Burlington, VT PHP Users Group Subversion Presentation
 

Kürzlich hochgeladen

Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 

Kürzlich hochgeladen (20)

Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 

Zend Framework Introduction

  • 1. Zend Framework Introduction Features and Common Patterns
  • 2. Examples from a demo blogging application named Postr are used throughout this presentation. You can view, download, or fork the demo web application on GitHub: http://github.com/bradley-holt/postr
  • 3. Zend_Tool Automated scaffolding of project and project components Used in creating the demo application, Postr Referenced throughout this presentation
  • 4. Zend_Tool Create a Project mkdir postr cd postr zf create project .
  • 5. Zend_Tool Project Structure .zfproject.xml application/ Bootstrap.php configs/ application.ini controllers/ ErrorController.php IndexController.php views/ scripts/ error/ error.phtml index/ index.phtml public/ .htaccess index.php tests/ application/ bootstrap.php library/ bootstrap.php phpunit.xml
  • 6. Front Controller All HTTP requests for the application go through one script. Apache’s rewrite module (or equivalent) makes this happen. See: Front Controller pattern public/index.php public/.htaccess
  • 7. Zend_Application Bootstraps the application Provides reusable resources Sets up PHP environment See: Zend_Application application/Bootstrap.php
  • 8. Con guration Default con guration is in application/configs/application.ini Allows for con guration sections; for example: • production • staging • testing • development Sections can inherit from other sections See: application/con gs/application.ini
  • 9. Name the Project Default application class name pre x is Application_. zf change application.class-name-prefix Postr_
  • 10. Updated Con guration Added to application/configs/application.ini: [production] appnamespace = "Postr_" See: application/con gs/application.ini
  • 11. Model-View-Controller (MVC) Composite of several design patterns Isolates domain logic from input and presentation Model: domain logic View: presentation layer Controller: interprets input and passes it to the Model; provides Model data to the View See: Model-view-controller application/models/ application/views/ application/controllers/
  • 12. Zend_Layout Implementation of the Two Step View pattern Allows for consistent layout across multiple pages Easier to manage than “includes” See: Zend_Layout Two Step View
  • 14. Zend_Layout Layout View Script application/ layouts/ scripts/ layout.phtml Added to application/configs/application.ini: [production] resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/" See: application/layouts/scripts/layout.phtml application/con gs/application.ini
  • 15. Controllers Connects the Model and the View Contains one or more actions URL based routing typically decides what controller and action to execute: :controller/:action Custom routing options available
  • 16. View Scripts PHP templates No domain logic please! Default suffix of .phtml One view script per controller action (by default)
  • 17. Create a Controller zf create controller Entry
  • 18. Entry Controller and View Script application/ controllers/ EntryController.php views/ scripts/ entry/ index.phtml tests/ application/ controllers/ EntryControllerTest.php See: application/controllers/EntryController.php application/views/scripts/entry/index.phtml tests/application/controllers/EntryControllerTest.php
  • 19. Create Additional Controller Actions zf create action new Entry zf create action get Entry zf create action edit Entry zf create action post Entry zf create action put Entry zf create action delete Entry
  • 20. Entry Actions Methods added to application/controllers/EntryController.php: newAction() getAction() editAction() postAction() putAction() deleteAction() See: application/controllers/EntryController.php
  • 21. Entry Actions View scripts created: application/ views/ scripts/ entry/ delete.phtml edit.phtml get.phtml new.phtml post.phtml put.phtml See: application/views/scripts/entry/
  • 22. Zend_Test Functional (end-to-end) testing of controllers Simulates HTTP requests to the application No web server required Also provides a DB testing facility See: Zend_Test Functional Test tests/application/controllers/EntryControllerTest.php
  • 23. Models Models are speci c to your domain No such thing as one-size- ts all models No Zend_Model However, some useful patterns have emerged
  • 24. Create a Model zf create model Entry
  • 25. Entry Model application/ models/ Entry.php See: application/models/Entry.php
  • 26. Zend_Form Input ltering Input validation Form and element rendering Huge time saver See: Zend_Form Zend_Filter Zend_Validate
  • 27. Zend_Form Create a Form zf create form Entry
  • 28. Zend_Form Entry Form application/ forms/ Entry.php See: application/forms/Entry.php
  • 29. Zend_Db_Table Object-oriented database interface Implements the Table Data Gateway and Row Data Gateway patterns See: Table Data Gateway Row Data Gateway
  • 30. Con gure a DB Adapter zf configure dbadapter "adapter=Pdo_Sqlite&dbname=../data/db/production.db" zf configure dbadapter "adapter=Pdo_Sqlite&dbname=../data/db/staging.db" -s staging zf configure dbadapter "adapter=Pdo_Sqlite&dbname=../data/db/testing.db" -s testing zf configure dbadapter "adapter=Pdo_Sqlite&dbname=../data/db/development.db" -s development
  • 31. Updated Con guration Added to application/configs/application.ini: [production] resources.db.adapter = "Pdo_Sqlite" resources.db.params.dbname = APPLICATION_PATH "/../data/db/production.db" [staging : production] resources.db.adapter = "Pdo_Sqlite" resources.db.params.dbname = APPLICATION_PATH "/../data/db/staging.db" [testing : production] resources.db.adapter = "Pdo_Sqlite" resources.db.params.dbname = APPLICATION_PATH "/../data/db/testing.db" [development : production] resources.db.adapter = "Pdo_Sqlite" resources.db.params.dbname = APPLICATION_PATH "/../data/db/development.db" See: application/con gs/application.ini
  • 32. Load DB Schema Project-speci c and not built-in to Zend Framework: mkdir -p data/db php scripts/load.sqlite.php See: scripts/load.sqlite.php scripts/schema.sqlite.sql
  • 33. Create DB Tables from the Database zf create dbtable.from-database
  • 34. Entry and Entry Tag DB Tables application/ models/ DbTable/ Entry.php EntryTag.php See: application/models/DbTable/Entry.php application/models/DbTable/EntryTag.php
  • 35. Data Mapper Keeps your domain logic isolated from your database implementation Domain objects should not directly use data mappers See: Data Mapper
  • 36. Create a Data Mapper zf create model EntryMapper
  • 37. Entry Mapper application/ models/ EntryMapper.php See: application/models/EntryMapper.php
  • 38. Zend_Paginator Pagination for database or any arbitrary data Several adapters available: • Array • DbSelect • DbTableSelect • Iterator • Null • Write your own in order to paginate domain objects See: Zend_Paginator
  • 39. Zend_Paginator Create a Paginator Adapter zf create model EntryPaginatorAdapter
  • 40. Zend_Paginator Entry Paginator Adapter application/ models/ EntryPaginatorAdapter.php See: application/models/EntryPaginatorAdapter.php
  • 41. Zend_Date Manipulate dates and times Useful for date and time calculations Allows for input from and output to various formats Used as a domain object in the Postr demo application: • Entry Updated • Entry Published See: Zend_Date application/models/Entry.php
  • 42. Zend_Markup Renders BBcode or Textile markup into HTML or other formats Extensible so may see other markup languages in the future Used in the Postr demo application: • Entry Content and Entry Summary are stored as Textile markup • Entry Content and Entry Summary can optionally be retrieved as HTML See: Zend_Markup BBCode Textile application/models/Entry.php
  • 43. Zend_Navigation Create menus, breadcrumbs, links, and sitemaps Used to create the menu navigation in the Postr demo application See: Zend_Navigation application/Bootstrap.php application/layouts/scripts/header.phtml
  • 44. Controller Plugins Allows developers to hook into various events during the controller process: • routeStartup() • dispatchLoopStartup() • preDispatch() • postDispatch() • dispatchLoopShutdown() • routeShutdown() See: Controller Plugins application/plugins/RouteContext.php
  • 45. References Bradley Holt’s demo application: Postr Zend Framework Quick Start Matthew Weier O’Phinney’s demo application: Pastebin Zend Framework Programmer’s Reference Guide
  • 46. Credits Author Bradley Holt Layout & Design Jason Pelletier This presentation licensed under Creative Commons—Attribution 3.0 United States License.