Creating fast, dynamic ACLs in Zend Framework (Zend Webinar)
Zend Framework Introduction
-
Upload
bradley-holt -
Category
Technology
-
view
13.556 -
download
0
description
Transcript of Zend Framework Introduction
![Page 1: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/1.jpg)
Features and Common Patterns
Zend Framework Introduction
![Page 2: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/2.jpg)
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
![Page 3: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/3.jpg)
Automated scaffolding of project and project components
Used in creating the demo application, Postr
Referenced throughout this presentation
Zend_Tool
![Page 4: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/4.jpg)
Zend_Tool
Create a Projectmkdir postrcd postrzf create project .
![Page 5: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/5.jpg)
Zend_Tool
Project Structure.zfproject.xmlapplication/ Bootstrap.php configs/ application.ini controllers/ ErrorController.php IndexController.php views/ scripts/ error/ error.phtml index/ index.phtmlpublic/ .htaccess index.phptests/ application/ bootstrap.php library/ bootstrap.php phpunit.xml
![Page 6: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/6.jpg)
Front ControllerAll HTTP requests for the application go through one script.Apache’s rewrite module (or equivalent) makes this happen.
See:Front Controller patternpublic/index.phppublic/.htaccess
![Page 7: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/7.jpg)
Zend_ApplicationBootstraps the application
Provides reusable resources
Sets up PHP environment
See:Zend_Applicationapplication/Bootstrap.php
![Page 8: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/8.jpg)
Con!gurationDefault 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
![Page 9: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/9.jpg)
Name the ProjectDefault application class name pre"x is Application_.zf change application.class-name-prefix Postr_
![Page 10: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/10.jpg)
Updated Con!gurationAdded to application/configs/application.ini:[production]appnamespace = "Postr_"
See:application/con"gs/application.ini
![Page 11: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/11.jpg)
Model-View-Controller (MVC)Composite of several design patternsIsolates domain logic from input and presentationModel: domain logicView: presentation layerController: interprets input and passes it to the Model; provides Model data to the View
See:Model-view-controllerapplication/models/application/views/application/controllers/
![Page 12: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/12.jpg)
Zend_LayoutImplementation of the Two Step View pattern
Allows for consistent layout across multiple pages
Easier to manage than “includes”
See:Zend_LayoutTwo Step View
![Page 13: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/13.jpg)
Zend_Layout
Enable Layoutzf enable layout
![Page 14: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/14.jpg)
Zend_Layout
Layout View Scriptapplication/ layouts/ scripts/ layout.phtml
Added to application/configs/application.ini:[production]resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
See:application/layouts/scripts/layout.phtmlapplication/con"gs/application.ini
![Page 15: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/15.jpg)
ControllersConnects 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
![Page 16: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/16.jpg)
View ScriptsPHP templates
No domain logic please!
Default suffix of .phtml
One view script per controller action (by default)
![Page 17: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/17.jpg)
Create a Controllerzf create controller Entry
![Page 18: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/18.jpg)
Entry Controller and View Scriptapplication/ controllers/ EntryController.php views/ scripts/ entry/ index.phtmltests/ application/ controllers/ EntryControllerTest.php
See:application/controllers/EntryController.phpapplication/views/scripts/entry/index.phtmltests/application/controllers/EntryControllerTest.php
![Page 19: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/19.jpg)
Create Additional Controller Actionszf create action new Entryzf create action get Entryzf create action edit Entryzf create action post Entryzf create action put Entryzf create action delete Entry
![Page 20: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/20.jpg)
Entry ActionsMethods added to application/controllers/EntryController.php:newAction()getAction()editAction()postAction()putAction()deleteAction()
See:application/controllers/EntryController.php
![Page 21: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/21.jpg)
Entry ActionsView scripts created:application/ views/ scripts/ entry/ delete.phtml edit.phtml get.phtml new.phtml post.phtml put.phtml
See:application/views/scripts/entry/
![Page 22: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/22.jpg)
Zend_TestFunctional (end-to-end) testing of controllers
Simulates HTTP requests to the application
No web server required
Also provides a DB testing facility
See:Zend_TestFunctional Testtests/application/controllers/EntryControllerTest.php
![Page 23: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/23.jpg)
ModelsModels are speci"c to your domainNo such thing as one-size-"ts all modelsNo Zend_ModelHowever, some useful patterns have emerged
![Page 24: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/24.jpg)
Create a Modelzf create model Entry
![Page 25: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/25.jpg)
Entry Modelapplication/ models/ Entry.php
See:application/models/Entry.php
![Page 26: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/26.jpg)
Zend_FormInput "ltering
Input validation
Form and element rendering
Huge time saver
See:Zend_FormZend_FilterZend_Validate
![Page 27: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/27.jpg)
Zend_Form
Create a Formzf create form Entry
![Page 28: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/28.jpg)
Zend_Form
Entry Formapplication/ forms/ Entry.php
See:application/forms/Entry.php
![Page 29: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/29.jpg)
Zend_Db_TableObject-oriented database interface
Implements the Table Data Gateway and Row Data Gateway patterns
See:Table Data GatewayRow Data Gateway
![Page 30: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/30.jpg)
Con!gure a DB Adapterzf configure dbadapter "adapter=Pdo_Sqlite&dbname=../data/db/production.db"zf configure dbadapter "adapter=Pdo_Sqlite&dbname=../data/db/staging.db" -s stagingzf configure dbadapter "adapter=Pdo_Sqlite&dbname=../data/db/testing.db" -s testingzf configure dbadapter "adapter=Pdo_Sqlite&dbname=../data/db/development.db" -s development
![Page 31: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/31.jpg)
Updated Con!gurationAdded 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
![Page 32: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/32.jpg)
Load DB SchemaProject-speci"c and not built-in to Zend Framework:mkdir -p data/db
php scripts/load.sqlite.php
See:scripts/load.sqlite.phpscripts/schema.sqlite.sql
![Page 33: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/33.jpg)
Create DB Tables from the Databasezf create dbtable.from-database
![Page 34: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/34.jpg)
Entry and Entry Tag DB Tablesapplication/ models/ DbTable/ Entry.php EntryTag.php
See:application/models/DbTable/Entry.phpapplication/models/DbTable/EntryTag.php
![Page 35: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/35.jpg)
Data MapperKeeps your domain logic isolated from your database implementationDomain objects should not directly use data mappers
See:Data Mapper
![Page 36: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/36.jpg)
Create a Data Mapperzf create model EntryMapper
![Page 37: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/37.jpg)
Entry Mapperapplication/ models/ EntryMapper.php
See:application/models/EntryMapper.php
![Page 38: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/38.jpg)
Zend_PaginatorPagination 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
![Page 39: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/39.jpg)
Zend_Paginator
Create a Paginator Adapterzf create model EntryPaginatorAdapter
![Page 40: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/40.jpg)
Zend_Paginator
Entry Paginator Adapterapplication/ models/ EntryPaginatorAdapter.php
See:application/models/EntryPaginatorAdapter.php
![Page 41: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/41.jpg)
Zend_DateManipulate 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_Dateapplication/models/Entry.php
![Page 42: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/42.jpg)
Zend_MarkupRenders 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_MarkupBBCodeTextileapplication/models/Entry.php
![Page 43: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/43.jpg)
Zend_NavigationCreate menus, breadcrumbs, links, and sitemaps
Used to create the menu navigation in the Postr demo application
See:Zend_Navigationapplication/Bootstrap.phpapplication/layouts/scripts/header.phtml
![Page 44: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/44.jpg)
Controller PluginsAllows developers to hook into various events during the controller process:
• routeStartup()
• dispatchLoopStartup()
• preDispatch()
• postDispatch()
• dispatchLoopShutdown()
• routeShutdown()
See:Controller Pluginsapplication/plugins/RouteContext.php
![Page 45: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/45.jpg)
ReferencesBradley Holt’s demo application: Postr
Zend Framework Quick Start
Matthew Weier O’Phinney’s demo application: Pastebin
Zend Framework Programmer’s Reference Guide
![Page 46: Zend Framework Introduction](https://reader033.fdocuments.us/reader033/viewer/2022042814/55557bfab4c9055f5f8b4f4f/html5/thumbnails/46.jpg)
CreditsAuthorBradley Holt
Layout & DesignJason Pelletier
This presentation licensed under Creative Commons—Attribution 3.0 United States License.