SlideShare a Scribd company logo
My Very First…Model View Controller Web Applicationwith the Zend FrameworkNew York CityZF Meetup
Part OneWhy use an MVC framework?Inversion of Control makes life simpler.Setting up an environment for use with ZF.Creating a project with ZF tool.ZF application basics.
Why Use an MVC Framework?Helps to stay DRY (don’t repeat others either)Spend time on unique application problems, not plumbing problems.Take advantage of combined years of experience.Things you think of down the line already taken care of.Flexible, reliable, well tested code base:Unit tested.Community tested.
Inversion of ControlFramework != LibraryA library is a set of tools.A framework gives you a working structure to customize by hooking into key points.The framework invokes your code at the appropriate time (control is inverted).
Zend Framework MVC Framework + Components Library + CMD Tool MVC architecture.Useful components for everyday tasks:ACL + AuthForms: validation, filtering built inWeb services: Amazon, Twitter, etcCommand line tool eases set-up tasks.
Zend FrameworkUse at will:Components can be integrated into an app done with Lithium, Symfony, Wordpress, Drupal, etc.Large user community500 contributors, 10 million downloadsCorporate backing (+/-)Test driven development
           Background InfoMVC frameworks typicallyare made of:Controllers and action methods1 Action Method ≈ 1 PageControllers group action methodsView scriptsControl look and feel of appModelsApplication data
           Simple Example(find the code for a URL)In a ZF app, this URL:Maps to the “about action method” of the “index controller”
Simple ExampleThe “index controller” is a class.The “about action method” is a method of the IndexController class.
Simple ExampleAbout action is called by the framework and renders the “about view script”.
        Simple ExampleThe results of the view script are output.
Simple Example: SummaryFramework maps URL to an action method.You write one method and one view scriptFramework calls your code when it’s neededFramework presents view script to user
     Real Project: TasksWant an application to create, manage, and view my tasks.Users should be able to register.Users should be able to create, edit, and delete individual tasks.Users should be able to view a list of their tasks, or any single task.
    Tasks: So we’ll need…A user component.A registration component.A tasks component.Security to make sure: Only members can see other usersOnly members can do task stuffOnly the owner of a task can do stuff to her tasksetc
Set Up 1: ZF Command Line ToolDownload current version of ZFFolder will contain Zend library, and bin:Windows: Add bin to your PATH*nix: Create symbolic linkEven better, use PEAR installer!
Set Up 2: Zend library to Include PathCan add in php.iniCan add in application’s index.php file
       Step 1: Create ProjectUse ZF tool to create project structure.Must “enter” app directory for further tooling.
Step 1: Create Project“public” is the face of your application.Accessible to civiliansCSS, Javascript, other asset files go here.index.php is single point of entry..htaccess automatically created“application” is where most of the app lives.“library” is for app specific libraries.“tests” is for unit tests
Step 1: Create Projectzf create project creates an index controller with a default index action and script
Step 2: Modify Index Action OutputWant to put something specific to your app on public splash page.Need to:Modify the action methodModify the view scriptWhere are these files in app folder structure?
Step 2: Modify Index Action OutputOne controller class per file, View scripts housed in views/scriptsGrouped into folder named after “it’s controller”
Step 2: Modify Index Action OutputChange views/scripts/index/index.phtmlfrom this…
Step 2: Modify Index Action Output…to this:
Step 3: Variables in View ScriptsIn ZF, view is an objectView object is in charge of rendering scriptsView scripts execute inside of view objectView scripts have same scope as method of view objectIn other words, in script $this refers to the view objectController has reference to view objectController assigns variable to view object for use in view scriptsAssign as property of view object
Step 3: Variables in View ScriptsVariables assigned as view object properties in controller:
Step 3: Variables in View ScriptsVariables used as members of view object inside of view script:
Step 3: Variables in View Scripts
  Step 4: Create Another PageA Page ≈ An Action MethodCreate action methods using ZF toolCreates method body in controller and view script.Zf create action actionNamecontrollerItsIn(Note that you have to have created the controller using ZF tool to create an action in it using the tool)
Step 4: Create Another PageCreate an about page:
Step 4: Create Another PageAction body and view script magically created!
Step 4: Create Another PageModify view script as desired and presto!
Steps 5 – 8: UsersWant to be able to register usersWant to be able to store user dataWant to let users manage their dataWant to make sure only users can access user data
Steps 5 – 8: UsersSo we’ll need:A way to interact with a user database table (Zend_Db)A way for users to interact with information (Zend_Form)User pages (UserController)Log in and access control (Zend_Acl + Zend_Auth)
Steps 5 – 8: UsersStart with a Users table like so:
Step 5: Create UserControllerWe’ll put user related actions in the UserController.Use ZF tool to create the controller and actionsZf create controller controllerNameWill create controller class file, and view scripts directory
Step 5: Create UserController
Step 5: Create UserController
  Step 6: Using a DatabaseZF has adapter based access toDB tables.Most major DB server’s supportedMySQL, Postgre, Oracle, MSSQL, IBM DB2…Query against adapter  easier to make changes to backend without ripple effects in consumer code.Not Zend_Model
Step 6: Using a Database2 or 3 Steps:Create DB adapterOptionally, create tableUse it
Step 6: Using a DatabaseWe’ll use simple version (query against DB)For now, DB config in controller init methodThink of init as constructor hook
Step 6: Using a DatabaseMethod to insert is…insert!
Step 6: Using a DatabaseMethod to update is…update!
Step 6: Using a DatabaseMethod to delete is…delete!
Step 6: Using a DatabaseVarious methods for SELECT statements:fetchAllfetchAssocfetchNumfetchObj
Step 6: Using a Database
Step 6: Using a DatabaseMethods are similar when using Zend_Db_TableUsually configure DB in bootstrap
Step 7: Using FormsUsers need to be able to registerUse Zend_Form for registration formForms and form elements in ZF are objects:Add elements to form with addElementCan add validators to elements to ensure data integrityEmailAddressvalidatorInteger validatorMany more
ZF Tool and Forms
Add Elements to FormsElement name and type required
Create and Display a FormCreate in controller, assign to view, use Zend_Form::render() to display.
Handling Form SubmissionRequest variables held in request objectRequest object accessed in actionUse Zend_Controller_Request::isPost to test for form submissionUse Zend_Form::isValid() to test data validityUse Zend_Form::persistData() to save changesThis is what I do, other ways exist
Handling Form SubmissionAction controls flow, form controls data
Valid Data Submission
Invalid Data Submission
Zend FormAdd and configure form elementsUse Zend_Form::isValid() to test for data validityUse Zend_Form::persistData() to commit changesNote that step 3 can be done other ways
Step 8 (next time): Access ControlZend_AclRoles, Resources, PrivilegesZend_AuthAction helpersBasicsUse with access controlView helpersBasicsCommon helpers
New York City area Zend Framework Meetuphttp://www.meetup.com/ZendFramework-NYCmetro/Affiliated with http://www.nyphp.org/Thanks for attending “Your First Zend Framework Project” presented on Feb. 22, 2011 byIsaac Fosterhttp://www.linkedin.com/in/isaaczfosterisaac.z.foster@gmail.comAlan Seidenhttp://www.alanseiden.comalan@alanseiden.comTwitter: @alanseidenSign up to hear about all our ZF meetups at http://www.meetup.com/ZendFramework-NYCmetro/

More Related Content

PDF
Client-side JavaScript
PPTX
Flash Testing with Selenium RC
DOCX
LearningMVCWithLINQToSQL
PPTX
Web API with ASP.NET MVC by Software development company in india
PPTX
VIPER Architecture
PDF
Yii - Next level PHP Framework von Florian Facker
PPTX
Best Practices for Application Development with Box
PPT
introduction to Angularjs basics
Client-side JavaScript
Flash Testing with Selenium RC
LearningMVCWithLINQToSQL
Web API with ASP.NET MVC by Software development company in india
VIPER Architecture
Yii - Next level PHP Framework von Florian Facker
Best Practices for Application Development with Box
introduction to Angularjs basics

What's hot (20)

PPTX
iOS training (intermediate)
KEY
Introduction to ASP.NET MVC
PDF
Introduction To CodeIgniter
PPT
Ajax toolkit framework
PPTX
MVC Training Part 2
PPTX
Box Authentication Types
PDF
From mvc to viper
PDF
Asp dot-net core problems and fixes
PPT
Getting Started with Zend Framework
PPTX
Comparing Angular and React JS for SPAs
PPTX
Introduction to JSF
PPT
PDF
Enterprise Level Application Architecture with Web APIs using Entity Framewor...
PPTX
ATAGTR2017 Upgrading a mobile tester's weapons with advanced debugging
PDF
Introduction Yii Framework
PPTX
Angular interview questions
PPTX
Angular JS, A dive to concepts
PPT
10 reasons to choose the yii framework
PDF
Lab4 - android
PDF
Get things done with Yii - quickly build webapplications
iOS training (intermediate)
Introduction to ASP.NET MVC
Introduction To CodeIgniter
Ajax toolkit framework
MVC Training Part 2
Box Authentication Types
From mvc to viper
Asp dot-net core problems and fixes
Getting Started with Zend Framework
Comparing Angular and React JS for SPAs
Introduction to JSF
Enterprise Level Application Architecture with Web APIs using Entity Framewor...
ATAGTR2017 Upgrading a mobile tester's weapons with advanced debugging
Introduction Yii Framework
Angular interview questions
Angular JS, A dive to concepts
10 reasons to choose the yii framework
Lab4 - android
Get things done with Yii - quickly build webapplications
Ad

Similar to My Very First Zf App Part One (20)

PPT
Hnd201 Building Ibm Lotus Domino Applications With Ajax Plugins
PPT
Yii php framework_honey
PDF
Introduction to Andriod Studio Lecture note: Android Development Lecture 1.pdf
PPT
Vb basics
PPT
AspMVC4 start101
PPT
Introduction to Zend Framework
PPTX
Mvc summary
DOCX
A report on mvc using the information
PPT
Metamorphosis from Forms to Java: A technical lead's perspective, part II
PPT
visual basic for the beginner
DOCX
unit 4.docx
PPTX
Codeigniter
PPT
PPTX
8-9-10. ASP_updated8-9-10. ASP_updated8-9-10. ASP_updated
PPTX
MVC Frameworks for building PHP Web Applications
PPTX
Code camp 2011 Getting Started with IOS, Una Daly
PPTX
Yii framework
PPT
2007 Zend Con Mvc
PPTX
P H P Framework
PDF
Introduction of Xcode
Hnd201 Building Ibm Lotus Domino Applications With Ajax Plugins
Yii php framework_honey
Introduction to Andriod Studio Lecture note: Android Development Lecture 1.pdf
Vb basics
AspMVC4 start101
Introduction to Zend Framework
Mvc summary
A report on mvc using the information
Metamorphosis from Forms to Java: A technical lead's perspective, part II
visual basic for the beginner
unit 4.docx
Codeigniter
8-9-10. ASP_updated8-9-10. ASP_updated8-9-10. ASP_updated
MVC Frameworks for building PHP Web Applications
Code camp 2011 Getting Started with IOS, Una Daly
Yii framework
2007 Zend Con Mvc
P H P Framework
Introduction of Xcode
Ad

My Very First Zf App Part One

  • 1. My Very First…Model View Controller Web Applicationwith the Zend FrameworkNew York CityZF Meetup
  • 2. Part OneWhy use an MVC framework?Inversion of Control makes life simpler.Setting up an environment for use with ZF.Creating a project with ZF tool.ZF application basics.
  • 3. Why Use an MVC Framework?Helps to stay DRY (don’t repeat others either)Spend time on unique application problems, not plumbing problems.Take advantage of combined years of experience.Things you think of down the line already taken care of.Flexible, reliable, well tested code base:Unit tested.Community tested.
  • 4. Inversion of ControlFramework != LibraryA library is a set of tools.A framework gives you a working structure to customize by hooking into key points.The framework invokes your code at the appropriate time (control is inverted).
  • 5. Zend Framework MVC Framework + Components Library + CMD Tool MVC architecture.Useful components for everyday tasks:ACL + AuthForms: validation, filtering built inWeb services: Amazon, Twitter, etcCommand line tool eases set-up tasks.
  • 6. Zend FrameworkUse at will:Components can be integrated into an app done with Lithium, Symfony, Wordpress, Drupal, etc.Large user community500 contributors, 10 million downloadsCorporate backing (+/-)Test driven development
  • 7. Background InfoMVC frameworks typicallyare made of:Controllers and action methods1 Action Method ≈ 1 PageControllers group action methodsView scriptsControl look and feel of appModelsApplication data
  • 8. Simple Example(find the code for a URL)In a ZF app, this URL:Maps to the “about action method” of the “index controller”
  • 9. Simple ExampleThe “index controller” is a class.The “about action method” is a method of the IndexController class.
  • 10. Simple ExampleAbout action is called by the framework and renders the “about view script”.
  • 11. Simple ExampleThe results of the view script are output.
  • 12. Simple Example: SummaryFramework maps URL to an action method.You write one method and one view scriptFramework calls your code when it’s neededFramework presents view script to user
  • 13. Real Project: TasksWant an application to create, manage, and view my tasks.Users should be able to register.Users should be able to create, edit, and delete individual tasks.Users should be able to view a list of their tasks, or any single task.
  • 14. Tasks: So we’ll need…A user component.A registration component.A tasks component.Security to make sure: Only members can see other usersOnly members can do task stuffOnly the owner of a task can do stuff to her tasksetc
  • 15. Set Up 1: ZF Command Line ToolDownload current version of ZFFolder will contain Zend library, and bin:Windows: Add bin to your PATH*nix: Create symbolic linkEven better, use PEAR installer!
  • 16. Set Up 2: Zend library to Include PathCan add in php.iniCan add in application’s index.php file
  • 17. Step 1: Create ProjectUse ZF tool to create project structure.Must “enter” app directory for further tooling.
  • 18. Step 1: Create Project“public” is the face of your application.Accessible to civiliansCSS, Javascript, other asset files go here.index.php is single point of entry..htaccess automatically created“application” is where most of the app lives.“library” is for app specific libraries.“tests” is for unit tests
  • 19. Step 1: Create Projectzf create project creates an index controller with a default index action and script
  • 20. Step 2: Modify Index Action OutputWant to put something specific to your app on public splash page.Need to:Modify the action methodModify the view scriptWhere are these files in app folder structure?
  • 21. Step 2: Modify Index Action OutputOne controller class per file, View scripts housed in views/scriptsGrouped into folder named after “it’s controller”
  • 22. Step 2: Modify Index Action OutputChange views/scripts/index/index.phtmlfrom this…
  • 23. Step 2: Modify Index Action Output…to this:
  • 24. Step 3: Variables in View ScriptsIn ZF, view is an objectView object is in charge of rendering scriptsView scripts execute inside of view objectView scripts have same scope as method of view objectIn other words, in script $this refers to the view objectController has reference to view objectController assigns variable to view object for use in view scriptsAssign as property of view object
  • 25. Step 3: Variables in View ScriptsVariables assigned as view object properties in controller:
  • 26. Step 3: Variables in View ScriptsVariables used as members of view object inside of view script:
  • 27. Step 3: Variables in View Scripts
  • 28. Step 4: Create Another PageA Page ≈ An Action MethodCreate action methods using ZF toolCreates method body in controller and view script.Zf create action actionNamecontrollerItsIn(Note that you have to have created the controller using ZF tool to create an action in it using the tool)
  • 29. Step 4: Create Another PageCreate an about page:
  • 30. Step 4: Create Another PageAction body and view script magically created!
  • 31. Step 4: Create Another PageModify view script as desired and presto!
  • 32. Steps 5 – 8: UsersWant to be able to register usersWant to be able to store user dataWant to let users manage their dataWant to make sure only users can access user data
  • 33. Steps 5 – 8: UsersSo we’ll need:A way to interact with a user database table (Zend_Db)A way for users to interact with information (Zend_Form)User pages (UserController)Log in and access control (Zend_Acl + Zend_Auth)
  • 34. Steps 5 – 8: UsersStart with a Users table like so:
  • 35. Step 5: Create UserControllerWe’ll put user related actions in the UserController.Use ZF tool to create the controller and actionsZf create controller controllerNameWill create controller class file, and view scripts directory
  • 36. Step 5: Create UserController
  • 37. Step 5: Create UserController
  • 38. Step 6: Using a DatabaseZF has adapter based access toDB tables.Most major DB server’s supportedMySQL, Postgre, Oracle, MSSQL, IBM DB2…Query against adapter  easier to make changes to backend without ripple effects in consumer code.Not Zend_Model
  • 39. Step 6: Using a Database2 or 3 Steps:Create DB adapterOptionally, create tableUse it
  • 40. Step 6: Using a DatabaseWe’ll use simple version (query against DB)For now, DB config in controller init methodThink of init as constructor hook
  • 41. Step 6: Using a DatabaseMethod to insert is…insert!
  • 42. Step 6: Using a DatabaseMethod to update is…update!
  • 43. Step 6: Using a DatabaseMethod to delete is…delete!
  • 44. Step 6: Using a DatabaseVarious methods for SELECT statements:fetchAllfetchAssocfetchNumfetchObj
  • 45. Step 6: Using a Database
  • 46. Step 6: Using a DatabaseMethods are similar when using Zend_Db_TableUsually configure DB in bootstrap
  • 47. Step 7: Using FormsUsers need to be able to registerUse Zend_Form for registration formForms and form elements in ZF are objects:Add elements to form with addElementCan add validators to elements to ensure data integrityEmailAddressvalidatorInteger validatorMany more
  • 48. ZF Tool and Forms
  • 49. Add Elements to FormsElement name and type required
  • 50. Create and Display a FormCreate in controller, assign to view, use Zend_Form::render() to display.
  • 51. Handling Form SubmissionRequest variables held in request objectRequest object accessed in actionUse Zend_Controller_Request::isPost to test for form submissionUse Zend_Form::isValid() to test data validityUse Zend_Form::persistData() to save changesThis is what I do, other ways exist
  • 52. Handling Form SubmissionAction controls flow, form controls data
  • 55. Zend FormAdd and configure form elementsUse Zend_Form::isValid() to test for data validityUse Zend_Form::persistData() to commit changesNote that step 3 can be done other ways
  • 56. Step 8 (next time): Access ControlZend_AclRoles, Resources, PrivilegesZend_AuthAction helpersBasicsUse with access controlView helpersBasicsCommon helpers
  • 57. New York City area Zend Framework Meetuphttp://www.meetup.com/ZendFramework-NYCmetro/Affiliated with http://www.nyphp.org/Thanks for attending “Your First Zend Framework Project” presented on Feb. 22, 2011 byIsaac Fosterhttp://www.linkedin.com/in/isaaczfosterisaac.z.foster@gmail.comAlan Seidenhttp://www.alanseiden.comalan@alanseiden.comTwitter: @alanseidenSign up to hear about all our ZF meetups at http://www.meetup.com/ZendFramework-NYCmetro/