Building Rich Internet Applications with PHP and Zend Framework



Similar documents
Google Web Toolkit. Introduction to GWT Development. Ilkka Rinne & Sampo Savolainen / Spatineo Oy

Credits: Some of the slides are based on material adapted from

Performance Testing for Ajax Applications

Enabling AJAX in ASP.NET with No Code

How To Write An Ria Application

An introduction to creating Web 2.0 applications in Rational Application Developer Version 8.0

The Great Office 365 Adventure

This course provides students with the knowledge and skills to develop ASP.NET MVC 4 web applications.

ACCESSING THE PROGRESS OPENEDGE APPSERVER FROM PROGRESS ROLLBASE USING JSDO CODE

Rich Internet Applications

Experimenting in the domain of RIA's and Web 2.0

Web Applications Come of Age

GOA365: The Great Office 365 Adventure


AJAX Toolkit Framework

SAV2013: The Great SharePoint 2013 App Venture

Oracle Application Development Framework Overview

Developing ASP.NET MVC 4 Web Applications MOC 20486

ORACLE APPLICATION EXPRESS 5.0

Accessing Data with ADOBE FLEX 4.6

Java Development for the Cloud, present and future. Scott Rich Distinguished Engineer, IBM Rational

Migration and Developer Productivity Solutions Cloud, Mobile and Web Development Workshop

GUI and Web Programming

Software Development Interactief Centrum voor gerichte Training en Studie Edisonweg 14c, 1821 BN Alkmaar T:

CAKEPHP & EXTJS - RESPONSIVE WEB TECHNOLOGIES

Web Development with the Eclipse Platform

CREATE A CUSTOM THEME WEBSPHERE PORTAL

A Model of the Operation of The Model-View- Controller Pattern in a Rails-Based Web Server

What s New in IBM Web Experience Factory IBM Corporation

Whitepaper. Rich Internet Applications. Frameworks Evaluation. Document reference: TSL-SES-WP0001 Januar

MASTERTAG DEVELOPER GUIDE

How To Build A Web App

IT3504: Web Development Techniques (Optional)

Dynamic Web Programming BUILDING WEB APPLICATIONS USING ASP.NET, AJAX AND JAVASCRIPT

Introducing Apache Pivot. Greg Brown, Todd Volkert 6/10/2010

Term Paper. P r o f. D r. E d u a r d H e i n d l. H o c h s c h u l e F u r t w a n g e n U n i v e r s i t y. P r e s e n t e d T o :

Developing ASP.NET MVC 4 Web Applications

IBM Script Portlet for WebSphere Portal Release 1.1

design coding monitoring deployment Java Web Framework for the Efficient Development of Enterprise Web Applications

Framework as a master tool in modern web development

IT3503 Web Development Techniques (Optional)

Rich Internet Applications

Enhancing your Web Experiences with ASP.NET Ajax and IIS 7

WebSphere Business Monitor V7.0 Script adapter lab

How To Train Aspnet

IBM Digital Experience. Using Modern Web Development Tools and Technology with IBM Digital Experience

Tutorial: Building a Dojo Application using IBM Rational Application Developer Loan Payment Calculator

Develop PHP mobile apps with Zend Framework

WIRIS quizzes web services Getting started with PHP and Java

Data Visualization in Ext Js 3.4

Sitecore Dashboard User Guide

Overview. In the beginning. Issues with Client Side Scripting What is JavaScript? Syntax and the Document Object Model Moving forward with JavaScript

Short notes on webpage programming languages

Introduction to Tizen SDK Alpha. Taiho Choi Samsung Electronics

Nexawebホワイトペーパー. Developing with Nexaweb ~ Nexaweb to Improve Development Productivity and Maintainability

Visualizing an OrientDB Graph Database with KeyLines

The Learn-Verified Full Stack Web Development Program

Web application Architecture

Sabre Red Apps. Developer Toolkit Overview. October 2014

ASP &.NET. Microsoft's Solution for Dynamic Web Development. Mohammad Ali Choudhry Milad Armeen Husain Zeerapurwala Campbell Ma Seul Kee Yoon

Take full advantage of IBM s IDEs for end- to- end mobile development

Developing ASP.NET MVC 4 Web Applications Course 20486A; 5 Days, Instructor-led

ASP.NET: THE NEW PARADIGM FOR WEB APPLICATION DEVELOPMENT

Rich-Internet Anwendungen auf Basis von ColdFusion und Ajax

Web Testing. Main Concepts of Web Testing. Software Quality Assurance Telerik Software Academy

<Insert Picture Here> Michael Hichwa VP Database Development Tools Stuttgart September 18, 2007 Hamburg September 20, 2007

Automating Rich Internet Application Development for Enterprise Web 2.0 and SOA

Curl Building RIA Beyond AJAX

Introduction to Oracle Mobile Application Framework Raghu Srinivasan, Director Development Mobile and Cloud Development Tools Oracle

Lab - Building an Internet of Things Application Hands-On Lab

<Insert Picture Here> Betting Big on JavaServer Faces: Components, Tools, and Tricks

Client-side Web Engineering From HTML to AJAX

J j enterpririse. Oracle Application Express 3. Develop Native Oracle database-centric web applications quickly and easily with Oracle APEX

vtiger Customer Portal 4.2 User Manual

Visualizing a Neo4j Graph Database with KeyLines

IBM Rational Web Developer for WebSphere Software Version 6.0

SUBJECT CODE : 4074 PERIODS/WEEK : 4 PERIODS/ SEMESTER : 72 CREDIT : 4 TIME SCHEDULE UNIT TOPIC PERIODS 1. INTERNET FUNDAMENTALS & HTML Test 1

AUTOMATED CONFERENCE CD-ROM BUILDER AN OPEN SOURCE APPROACH Stefan Karastanev

ORACLE ADF MOBILE DATA SHEET

Table of contents. HTML5 Data Bindings SEO DMXzone

CrownPeak Java Web Hosting. Version 0.20

v7.1 SP2 What s New Guide

Slide.Show Quick Start Guide

Transition your MCPD Web Developer Skills to MCPD ASP.NET Developer 3.5 (VB)

Programmabilty. Programmability in Microsoft Dynamics AX Microsoft Dynamics AX White Paper

Microsoft Dynamics AX Windows 8 App Starter Kit. App Development Guide Version 1.0

Building Ajax Applications with GT.M and EWD. Rob Tweed M/Gateway Developments Ltd

Building an ASP.NET MVC Application Using Azure DocumentDB

Web Cloud Architecture

Lucy Zhang UI Developer Contact:

Aspire Systems - Experience in Digital Marketing and Social Media

Operational Decision Manager Worklight Integration

Transcription:

Building Rich Internet Applications with PHP and Zend Framework Stanislav Malyshev Software Architect, Zend Technologies IDG: RIAs offer the potential for a fundamental shift in the experience of Internet applications, leading to applications that come closer to delivering on the promise of the Internet. Copyright 2007, Zend Technologies Inc.

Overview Building RIAs with PHP & Zend RIAs: Advantages & Disadvantages Demo Why AJAX with PHP on Zend Framework? Code walkthrough What s next for RIAs with PHP on Zend? Future Demo Rich Internet Applications with PHP 11-Oct-07 Page 2

Rich Internet Applications Goal: Deliver desktop experience in the browser Advantages of RIAs: Ajax is a response to the need for a richer and more easily deployable interface in the browser Provide desktop-like feeling, including drag & drop, sliders, and UI changes without full page refreshes More responsive Less visible interaction with the server Asynchronous interaction with the server Leverage the deployment advantages of the browser Rich Internet Applications with PHP 11-Oct-07 Page 3

Rich Internet Applications Disadvantages of RIAs: Three tier architecture is significantly more complex Requires in-depth knowledge of an additional language and platform JavaScript & browser Few established standards Need to deal with cross-browser compatibility Not many tools in existence Rich Internet Applications with PHP 11-Oct-07 Page 4

Demo A Chat Sample Application Credits: Stas Malyshev Pádraic Brady Sébastien Gruhier Rich Window prototype script.aculo.us Copyright 2007, Zend Technologies Inc.

Code Walkthough Framework MVC Data handling Search Services communication Rich Internet Applications with PHP 11-Oct-07 Page 6

PHP 5 open-source web framework Object-oriented, unit-tests required, & focused on best practices for modern web apps Follows principle of extreme simplicity, making it easy to learn and easy to use for developers Community-based led by team at Zend Open-source process, hosted at http://framework.zend.com under a business-friendly new BSD license Corporate contributions: Rich Internet Applications with PHP 11-Oct-07 Page 7

Zend Framework Architecture Rich Internet Applications with PHP 11-Oct-07 Page 8

What is the MVC component? The heart of ZF web applications Model: domain-specific data View: renders data to UI PHP-based template engine Controller: processes events, invokes changes in model VIEW CONTROLLER MODEL Simple solution for most apps Sensible defaults are built-in Flexible and extensible Supports advanced applications Rich Internet Applications with PHP 11-Oct-07 Page 9

How to use MVC: controllers Controller classes handle groups of request URLs http://zend.com/controller/action The default controller class is IndexController Action methods in each controller class handle individual requests http://zend.com/controller/action The default action method is indexaction() Rich Internet Applications with PHP 11-Oct-07 Page 10

Chat Application structure IndexController / (index) / (index) /name /message /chat LogController /log / (index) /log /search ServiceController /service /keyword /flickr /amazon Rich Internet Applications with PHP 11-Oct-07 Page 11

Controller Actions Each controller action method is responsible for doing one specific task e.g., IndexController: init() for setup Index is default for UI view Message & Name are the AJAX action callbacks Controller binds model and view together Message & Name don t get rendered by Zend_View_Renderer, but just return data Rich Internet Applications with PHP 11-Oct-07 Page 12

MVC entry point: index.php <?php // Get previous session data from.xml file $config = new Zend_Config(array(), true); $config->datafile = './data/chat.xml'; // Store the config for other parts to use Zend_Registry::set('config', $config); // Setup and run the Front Controller $controller = Zend_Controller_Front::getInstance(); $controller->setcontrollerdirectory('./application/controllers'); $controller->throwexceptions(true); // Exceptions ON for dev mode // Go! $controller->dispatch();?> Rich Internet Applications with PHP 11-Oct-07 Page 13

Model class ChatData Encapsulates: Session history Search data Implementation: SimpleXML Zend_Search_Lucene Rich Internet Applications with PHP 11-Oct-07 Page 14

Model: XML handling Loading data $this->_xml = simplexml_load_file($file); Adding new message $newmessage = $this->_xml->addchild('message'); $newmessage->addchild('author', $author); $newmessage->addchild('timestamp', time()); $newmessage->addchild('text', $message); Saving data $this->_xml->asxml($this->_filename); Checking new messages $newmessages = $this->_xml->xpath("/chat/message[timestamp>$last]"); Rich Internet Applications with PHP 11-Oct-07 Page 15

Model: Search handling Indexing $index = Zend_Search_Lucene::open($indexfile); $messages = $this->getnewmessages($since); foreach($messages as $newmsg) { $doc = new Zend_Search_Lucene_Document(); $doc->addfield(zend_search_lucene_field::unindexed('timestamp', $newmsg['timestamp'])); $doc->addfield(zend_search_lucene_field::text('author', $newmsg['author'])); $doc->addfield(zend_search_lucene_field::text('text', $newmsg['text'])); $index->adddocument($doc); } Searching $index = Zend_Search_Lucene::open($indexfile); $hits = $index->find($query); return $hits; Rich Internet Applications with PHP 11-Oct-07 Page 16

View Each action has its own view template Templates rendered automatically Unless requested not to, i.e. $this->_helper->viewrenderer-> setnorender(true); Rich Internet Applications with PHP 11-Oct-07 Page 17

View: displaying data Display search results <? if(count($this->hits)) {?> <span class="searchterm">looking for '<?= $this->query;?>':</span><br/> <? foreach($this->hits as $message) {?> [<?= date('c', $message->timestamp)?>] <span class="screenname"><?= $message->author;?></span>: <span class="msgtext"><?= $message->text;?></span> <br/> <? } // if(count($this->hits)) } else {?> Nothing found for '<?= $this->query;?>', sorry. <? }?> Rich Internet Applications with PHP 11-Oct-07 Page 18

AJAX communication - JSON PHP data to JSON // This function returns JSON (not a template), // so don t render a template $this->_helper->viewrenderer->setnorender(true); $phpmessagearray = $data->getnewmessages($last); $onlineusersarray = $data->getonlineusers(); $jsonarray = array('newmessages'=>$phpmessagearray, 'onlineusers'=>$onlineusersarray); $responsejson = Zend_Json::encode($jsonArray); $this->getresponse()->setheader('content-type', 'text/plain'); $this->getresponse()->setbody($responsejson); Rich Internet Applications with PHP 11-Oct-07 Page 19

AJAX communication - JSON XML to JSON $uri = 'http://search.yahooapis.com'; $service = '/ContentAnalysisService/V1/termExtraction'; $request = array('appid => $this->yahoo_key, 'context' => $text, 'output' => 'xml' ); $rest = new Zend_Rest_Client(); $rest->seturi($uri); $response = $rest->restpost($service, $request); $this->getresponse()->setheader('content-type', 'text/plain'); $this->getresponse()->setbody( Zend_Json::fromXML($response->getBody())); Rich Internet Applications with PHP 11-Oct-07 Page 20

Handling services - Flickr $flickr = new Zend_Service_Flickr($this->flickr_key); $flickrsearchptions = array('page'=>1, 'sort'=>'interestingness-desc'); $results = $flickr->tagsearch($keywords,$flickrsearchptions); // Collect results into PHP array $phpres = array(); foreach($results as $result) { $newres = array(); $newres['id'] = $result->id; $newres['title'] = $result->title; $img = $result->small; $newres['src'] = $img->uri; $newres['w'] = $img->width; $newres['h'] = $img->height; $newres['clickuri'] = @$result->original->clickuri; $phpres[] = $newres; } // Send the results out as JSON data $this->getresponse()->setheader('content-type', 'text/plain'); $this->getresponse()->setbody(zend_json::encode($phpres)); Rich Internet Applications with PHP 11-Oct-07 Page 21

What s next? AJAX-enabled Form component in Zend Framework Working on requirements and proposal AJAX support in development tools Eclipse-based JavaScript editing syntax highlighting, code completion JavaScript debugging Toolkit support (for instance, class browsers) Opens up opportunity for using Flex Significantly grow support for Web Services vendors Important enhancements to our Lucene implementation Range queries, wildcard queries Support for Lucene 2.3 file format (faster, better, backwards compatible, ) Rich Internet Applications with PHP 11-Oct-07 Page 22

Zend Component Model What? Toolkit for building AJAX applications How? Building blocks model a-la VB/Delphi/ASP/JSF Why? RAD in PHP spirit simplicity + power Rich Internet Applications with PHP 11-Oct-07 Page 23

Zend Component Model Zend Framework Component model PHP component architecture Server side messaging & persistence Ajax controller Ajax Toolkit Client side messaging Client-server connectivity Zend Studio (Eclipse) Drag&drop of components Component configuration Ajax Toolkit support (class browsing, documentation, etc.) Javascript editing and debugging Advanced CSS support Cross language debugging (stepping from Javascript into PHP) Rich Internet Applications with PHP 11-Oct-07 Page 24

Zend Component Model Component architecture Both visual and non-visual components Rich-design time experience ala Delphi and Visual Basic Drag&drop of components onto the Web page Component is self-contained incl. design and run-time rendering & property editors IDEs don t have to be hard coded per-component Encourages eco-system of components WYSIAWYG Programmatic model PHP developers like code and not declarative syntax Rich Internet Applications with PHP 11-Oct-07 Page 25

What are components? PHP+JS+CSS client/server side bundle Self-describing components can be used with any tool Visual RAD design time view no data required production view - reflects actual data Vi-compatibility no additional configurations or declarative syntax files, only PHP and CSS/JS on client side Extensibility new components, extending existing components Rich Internet Applications with PHP 11-Oct-07 Page 26

Components Demo Rich Internet Applications with PHP 11-Oct-07 Page 27

Components Demo Table component GMap component Button component Frame component containing Table component Rich Internet Applications with PHP 11-Oct-07 Page 28

Demo Server code setup() <?php class My_Page extends Zend_Component_Page { function setup() { $this->db1 = $this->create('db_table', 'DB1'); $this->db1->driver = 'PDO_MYSQL'; $this->contactstable = $this->create('ajax_table_paged', 'ContactsTable'); $this->contactstable->data = 'DB1'; $this->contactstable->rows = 10; $this->map = $this->create('google_map', 'Map'); $this->addbutton = $this->create('button', 'AddButton'); $this->addbutton->text = "Add to favorites"; } } $page = new My_Page(); Rich Internet Applications with PHP 11-Oct-07 Page 29

Demo Server code - presentation <html> <head><title>zend Components Demo App</title> <link type="text/css" rel="stylesheet" href="<?= $page->staticurl('demo.css')?>" /> <? $page->head();?></head> <body> <? $page->db1->show();?> <div id="page"> <div id="header"><h1>zend Components Example App</h1></div> <h2>contacts</h2> <div id="contactstable" class="box"> <? $page->contactstable->show();?></div> <span id="addbutton"><? $page->addbutton->show();?></span> <div id="map"><? $page->map->show();?></div> <script> </script> </body> </html> Rich Internet Applications with PHP 11-Oct-07 Page 30

Component Rendering Client Browser http//example.com/demo.php Server page /var/www/html/demo.php Rich Internet Applications with PHP 11-Oct-07 Page 31

Demo Client code function mkurl(data) { if(data[1]) { return ["/cm/getdata.php?id="+data[1][0]]; } } zcconnect(zc_contactstable, "selected", ZC_Map, "address", mkaddress); zcconnect(zc_contactstable, "selected", ZC_AddressFrame, "load", mkurl); zcconnect(zc_db3, "datachanged", ZC_FavoritesTable, "refresh"); zcconnect(zc_favoritestable, "selected", ZC_Map, "address", mkaddress2); zcconnect(zc_cleanbutton, "click", ZC_DB3, "clean"); zcconnect(zc_removebutton, "click", ZC_DB3, "remove", delfav); zcconnect(zc_addbutton, "click", ZC_DB3, "add", addfav); Rich Internet Applications with PHP 11-Oct-07 Page 32

render render render Component Interaction Client HTML page Component 1 JS Event Component 2 JS Event Component 3 AJAX call Component 1 Server-Side Bus Component 2 Method Calls Component 3 Server PHP page Persistent state Rich Internet Applications with PHP 11-Oct-07 Page 33

Interaction Scenario Client HTML page Add button add Data Store update Favorites Table *updated!* Click! adddata loaddata Add button Data Store getdata Favorites Table store load Server PHP page Persistent state Rich Internet Applications with PHP 11-Oct-07 Page 34

Zend Component Model - Future Component nesting Drag & drop support Visual event wiring Event standardization Tools for extending components Rich Internet Applications with PHP 11-Oct-07 Page 35

Thanks! Stanislav Malyshev stas@zend.com Please send feedback! http://devzone.zend.com/article/2442-php-and-ria Copyright 2007, Zend Technologies Inc.