Zend Framework Introduction
Upcoming SlideShare
Loading in...5
×
 

Zend Framework Introduction

on

  • 15,414 views

Features and patterns in Zend Framework

Features and patterns in Zend Framework

Statistics

Views

Total Views
15,414
Views on SlideShare
14,200
Embed Views
1,214

Actions

Likes
11
Downloads
253
Comments
0

34 Embeds 1,214

http://bradley-holt.blogspot.com 771
http://bradley-holt.com 166
http://www.slideshare.net 117
http://bradley-holt.blogspot.in 50
http://bradley-holt.blogspot.co.uk 21
http://bradley-holt.blogspot.ca 13
http://bradley-holt.blogspot.fr 10
http://bradley-holt.blogspot.de 7
http://bradley-holt.blogspot.com.br 6
http://bradley-holt.blogspot.jp 6
http://bradley-holt.blogspot.it 5
http://bradley-holt.blogspot.com.au 5
http://bradley-holt.blogspot.cz 4
http://bradley-holt.blogspot.nl 4
http://bradley-holt.blogspot.com.es 4
http://bradley-holt.blogspot.sg 3
http://bradley-holt.blogspot.gr 2
http://webcache.googleusercontent.com 2
http://bradley-holt.blogspot.ru 2
http://bradley-holt.blogspot.com.ar 2
http://bradley-holt.blogspot.pt 1
http://bradley-holt.blogspot.co.at 1
http://bradley-holt.blogspot.no 1
http://bradley-holt.blogspot.ie 1
http://bradley-holt.blogspot.co.il 1
http://bradley-holt.blogspot.se 1
http://quigonjinn03.appspot.com 1
http://translate.googleusercontent.com 1
http://bradley-holt.blogspot.hu 1
http://www.lmodules.com 1
https://twitter.com 1
http://liveweb.archive.org 1
http://quigonjinn03.appspot.com 1
http://bradley-holt.blogspot.mx 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution License

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

    Zend Framework Introduction Zend Framework Introduction Presentation Transcript

    • 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.