My Very First… Model View Controller Web Application with the Zend Framework New York City ZF Meetup.

Slides:



Advertisements
Similar presentations
WordPress Installation for Beginners Sheila Bergman
Advertisements

PHP Form and File Handling
PHP + Framework + MVC. What is Framework? Common code - Generic functionality Extensible - Specific functionality Unlike library – Flow Dictated by.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 15 Introduction to Rails.
Ian J Robotham Software Development Lead Medi-CAL Unit, University of Aberdeen.
MySQL Installation Guide. MySQL Downloading MySQL Installer.
CIS 4004: Web Based Information Technology Spring 2013
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
Web Applications Development Using Coldbox Platform Eddie Johnston.
Easy Website Creation Using WordPress Welcome and Thank You to our Sponsors.
1 Chapter 12 Working With Access 2000 on the Internet.
PHP (2) – Functions, Arrays, Databases, and sessions.
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
Database Updates Made Easy In WebFocus Using SQL And HTML Painter Sept 2011 Lender Processing Services 1.
Working with SharePoint Document Libraries. What are document libraries? Document libraries are collections of files that you can share with team members.
Drupal Workshop Introduction to Drupal Part 1: Web Content Management, Advantages/Disadvantages of Drupal, Drupal terminology, Drupal technology, directories.
Microsoft Windows 2003 Server. Client/Server Environment Many client computers connect to a server.
Windows.Net Programming Series Preview. Course Schedule CourseDate Microsoft.Net Fundamentals 01/13/2014 Microsoft Windows/Web Fundamentals 01/20/2014.
Installing CiviCRM onto Wordpress. How does it work?
ZFApp Preview Walkthrough. What is ZFApp? ZFApp is an application framework built on top of Zend Framework Fully compatible with the latest ZF Versions.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
CSCI 6962: Server-side Design and Programming
Server-side Scripting Powering the webs favourite services.
4-1 INTERNET DATABASE CONNECTOR Colorado Technical University IT420 Tim Peterson.
Web Application Development. Define ER model in QSEE Generate SQL Create Database mySQL Write Script to use TableEditor class Process to create A simple.
Web Application Development. Tools to create a simple web- editable database QSEE MySQL (or PHPMyAdmin) PHP TableEditor.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
Codeigniter is an open source web application. It occupies a very small amount of space in the memory and is most useful for developers who aim to develop.
COLD FUSION Deepak Sethi. What is it…. Cold fusion is a complete web application server mainly used for developing e-business applications. It allows.
Copyright © 2007, Oracle. All rights reserved. Managing Concurrent Requests.
Drupal Jumpstart Information Systems 337 Prof. Harry Plantinga.
SQL Queries Relational database and SQL MySQL LAMP SQL queries A MySQL Tutorial and applications Database Building Assignment.
School of Computing and Information Systems CS 371 Web Application Programming CakePHP Server-side Framework.
Domain 3 Understanding the Adobe Dreamweaver CS5 Interface.
PHP + Framework + MVC CakePHP Lectures 1. What is Framework? CakePHP Lectures 2.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
CSCI 6962: Server-side Design and Programming Database Manipulation in ASP.
Seattle Drupal Clinic Introduction to Drupal Part 1: Web Content Management, Advantages/Disadvantages of Drupal, Drupal terminology.
 Database Administration Installing Oracle 11g & Creating Database.
Building Secure Web Applications With ASP.Net MVC.
Rails & Ajax Module 5. Introduction to Rails Overview of Rails Rails is Ruby based “A development framework for Web-based applications” Rails uses the.
3 Copyright © 2004, Oracle. All rights reserved. Working in the Forms Developer Environment.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
 Empowers to your customer  Product Rating and its Management in Ecommerce Framework  Product Reviews and Management: Collecting customer opinion about.
 Shopping Basket  Stages to maintain shopping basket in framework  Viewing Shopping Basket.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Date : 3/04/2010 Web Technology Solutions Class: PHP Web Application Frameworks.
SPI NIGHTLIES Alex Hodgkins. SPI nightlies  Build and test various software projects each night  Provide a nightlies summary page that displays all.
® IBM Software Group © 2006 IBM Corporation Rational Asset Manager v7.2 Using Scripting Tutorial for using command line and scripting using Ant Tasks Carlos.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
Intro to APACHE, MySQL, and PHP & freely available (hackable) Packages Aonghus Sugrue 04 Oct 2012.
: Information Retrieval อาจารย์ ธีภากรณ์ นฤมาณนลิณี
Basics Components of Web Design & Development Basics, Components, Design and Development.
How to use Drupal Awdhesh Kumar (Team Leader) Presentation Topic.
COM621: Advanced Interactive Web Development Lecture 10 PHP and MySQL.
Web Technology Solutions
Introduction to Dynamic Web Programming
Play Framework: Introduction
Haritha Dasari Josue Balandrano Coronel -
PHP Training at GoLogica in Bangalore
PHP / MySQL Introduction
…and web frameworks in general
MVC Framework, in general.
ISC440: Web Programming 2 Server-side Scripting PHP 3
Easy Website Creation Using WordPress
Lecture 2 - SQL Injection
PHP and Forms.
Developing a Model-View-Controller Component for Joomla
…and web frameworks in general
Mr. Justin “JET” Turner CSCI 3000 – Fall 2016 Section DA MW 4:05-5:20
Presentation transcript:

My Very First… Model View Controller Web Application with the Zend Framework New York City ZF Meetup

Part One Why 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 Control Framework != Library A 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 + Auth – Forms: validation, filtering built in – Web services: Amazon, Twitter, etc Command line tool eases set-up tasks.

Zend Framework Use at will: – Components can be integrated into an app done with Lithium, Symfony, Wordpress, Drupal, etc. Large user community – 500 contributors, 10 million downloads – Corporate backing (+/-) Test driven development

Background Info MVC frameworks typically are made of: – Controllers and action methods 1 Action Method ≈ 1 Page Controllers group action methods – View scripts Control look and feel of app – Models Application 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 Example The “index controller” is a class. The “about action method” is a method of the IndexController class.

Simple Example About action is called by the framework and renders the “about view script”.

Simple Example The results of the view script are output.

Simple Example: Summary Framework maps URL to an action method. You write one method and one view script Framework calls your code when it’s needed Framework presents view script to user

Real Project: Tasks Want 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 users – Only members can do task stuff – Only the owner of a task can do stuff to her tasks – etc

Set Up 1: ZF Command Line Tool Download current version of ZF Folder will contain Zend library, and bin: – Windows: Add bin to your PATH – *nix: Create symbolic link Even better, use PEAR installer!

Set Up 2: Zend library to Include Path Can add in php.ini Can add in application’s index.php file

Step 1: Create Project Use 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 civilians – CSS, 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 Project zf create project creates an index controller with a default index action and script

Step 2: Modify Index Action Output Want to put something specific to your app on public splash page. Need to: – Modify the action method – Modify the view script Where are these files in app folder structure?

Step 2: Modify Index Action Output One controller class per file, View scripts housed in views/scripts – Grouped into folder named after “it’s controller”

Step 2: Modify Index Action Output Change views/scripts/index/index.phtml from this…

Step 2: Modify Index Action Output …to this:

Step 3: Variables in View Scripts In ZF, view is an object View object is in charge of rendering scripts View scripts execute inside of view object View scripts have same scope as method of view object – In other words, in script $this refers to the view object Controller has reference to view object Controller assigns variable to view object for use in view scripts – Assign as property of view object

Step 3: Variables in View Scripts Variables assigned as view object properties in controller:

Step 3: Variables in View Scripts Variables used as members of view object inside of view script:

Step 3: Variables in View Scripts

Step 4: Create Another Page A Page ≈ An Action Method Create action methods using ZF tool – Creates method body in controller and view script. – Zf create action actionName controllerItsIn – (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 Page Create an about page:

Step 4: Create Another Page Action body and view script magically created!

Step 4: Create Another Page Modify view script as desired and presto!

Steps 5 – 8: Users Want to be able to register users Want to be able to store user data Want to let users manage their data Want to make sure only users can access user data

Steps 5 – 8: Users So 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: Users Start with a Users table like so:

Step 5: Create UserController We’ll put user related actions in the UserController. Use ZF tool to create the controller and actions – Zf create controller controllerName – Will create controller class file, and view scripts directory

Step 5: Create UserController

Step 6: Using a Database ZF has adapter based access to DB tables. – Most major DB server’s supported MySQL, 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 Database 2 or 3 Steps: – Create DB adapter – Optionally, create table – Use it

Step 6: Using a Database We’ll use simple version (query against DB) For now, DB config in controller init method – Think of init as constructor hook

Step 6: Using a Database Method to insert is…insert!

Step 6: Using a Database Method to update is…update!

Step 6: Using a Database Method to delete is…delete!

Step 6: Using a Database Various methods for SELECT statements: – fetchAll – fetchAssoc – fetchNum – fetchObj

Step 6: Using a Database

Methods are similar when using Zend_Db_Table Usually configure DB in bootstrap

Step 7: Using Forms Users need to be able to register Use Zend_Form for registration form Forms and form elements in ZF are objects: – Add elements to form with addElement – Can add validators to elements to ensure data integrity Address validator Integer validator Many more

ZF Tool and Forms

Add Elements to Forms Element name and type required

Create and Display a Form Create in controller, assign to view, use Zend_Form::render() to display.

Handling Form Submission Request variables held in request object Request object accessed in action – Use Zend_Controller_Request::isPost to test for form submission – Use Zend_Form::isValid() to test data validity – Use Zend_Form::persistData() to save changes This is what I do, other ways exist

Handling Form Submission Action controls flow, form controls data

Valid Data Submission

Invalid Data Submission

Zend Form Add and configure form elements Use Zend_Form::isValid() to test for data validity Use Zend_Form::persistData() to commit changes – Note that step 3 can be done other ways

Step 8 (next time): Access Control Zend_Acl – Roles, Resources, Privileges Zend_Auth Action helpers – Basics – Use with access control View helpers – Basics – Common helpers

Isaac Fosterhttp:// New York City area Zend Framework Meetup Affiliated with Alan Seidenhttp:// Thanks for attending “Your First Zend Framework Project” presented on Feb. 22, 2011 by Sign up to hear about all our ZF meetups at