100% found this document useful (1 vote)
505 views30 pages

Rich Internet Applications With PHP

RIAs offer the potential for a fundamental shift in the experience of Internet applications. RIAs deliver desktop like feeling including drag&drop, sliders, and UI changes without full page refreshes. Ajax is also rated as high impact and capable of reaching maturity in less than two years. Close to half of developers surveyed say they are already working with Ajax or plan to do so in the coming year.

Uploaded by

alifr
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
505 views30 pages

Rich Internet Applications With PHP

RIAs offer the potential for a fundamental shift in the experience of Internet applications. RIAs deliver desktop like feeling including drag&drop, sliders, and UI changes without full page refreshes. Ajax is also rated as high impact and capable of reaching maturity in less than two years. Close to half of developers surveyed say they are already working with Ajax or plan to do so in the coming year.

Uploaded by

alifr
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 30

Rich Internet

Applications with PHP


PHP delivers modern Web applications

Stanislav Malyshev
Zend Technologies

IDC: RIA 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.


Rich Internet Applications

• Goal: Delivering the desktop experience in the


browser

• Advantages of RIAs:
 Richer user interfaces
• 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
 Ajax is a response to the need for a richer and easily
deployable interface in the browser

|
Rich Internet Applications with PHP Mar 10, 2008 Page
Disadvantages of RIA

• Three tier architecture is significantly more


complex

• Requires in-depth knowledge of an additional


language and platform, Javascript & the browser
• Few established standards
• Need to deal with cross-browser compatibility
• Few tools in existence
|
Rich Internet Applications with PHP Mar 10, 2008 Page
Ajax Momentum

Gartner, 2006:

Ajax is also rated as high impact and capable of reaching



maturity in less than two years. …  High levels of impact and
business value can only be achieved when the development
process encompasses innovations in usability and reliance on


complementary server-side processing (as is done in Google
Maps).

John F. Andrews, President, Evans Data Corporation, 2007:

“ Close to half of developers surveyed say they are already


working with AJAX or plan to do so in the coming year.


Consistent with the increasing adoption of web services we
are also seeing the same for AJAX. This framework, now more
than ever, is allowing developers the means to make web-


based applications function more like desktop ones.

|
Making Zend Rich Mar 10, 2008 Page
PHP & Web 2.0

|
Rich Internet Applications with PHP Mar 10, 2008 Page
PHP == Web Integration

|
Rich Internet Applications with PHP Mar 10, 2008 Page
PHP Ajax Projects

Amodules3, AJASON, AjaxAC,


Cajax, HTS, jPOP, Stratos
Framework, PAJAX, PAJAJ,
Flexible Ajax, Tiny Ajax,
SimpleJax, phpwebbuilder,
SAJAX, sniPEAR

|
Rich Internet Applications with PHP Mar 10, 2008 Page
PHP and Ajax - Simplicity

Embedded HTML
<div id="DataTable"><?php $page->DataTable->show(); ?></div>

JSON

$json = Zend_Json::encode($phpNative);

$phpNative = Zend_Json::decode($encodedValue);

|
Rich Internet Applications with PHP Mar 10, 2008 Page
PHP and Ajax - Simplicity

• PHP enables overloading of OO syntax both


from extensions and user-land classes
• Enables exposing OO-like models natively
(XML, SOAP, Java, …)

SimpleXML

<?php

$clients = simplexml_load_file('clients.xml');
foreach($clients as $client) {
print "{$client->name} is {$client->desc}\n";
}
?>

|
Rich Internet Applications with PHP Mar 10, 2008 Page
PHP for Microsoft Ajax library

<?php

require_once '../../dist/MSAjaxService.php';

class HelloService extends MSAjaxService


{
function SayHello($name)
{
return "Hello, " . $name . "!";
}
<html>
}
<head>
<title>Hello, World!</title>
$h = new HelloService();
<script type="text/javascript" src="../../MicrosoftAjaxLibrary/MicrosoftAjax.js"></script>
$h->ProcessRequest();
<script type="text/javascript" src="HelloService.php/js"></script>
</head>
?>
<body>
Name: <input id="name" type="text" />
<input type="button" value="Say Hello" onclick="button_click(); return false;" />
<br />
Response from server: <span id="response"></span>
</body>
<script type="text/javascript">
function button_click() {
HelloService.SayHello($get('name').value, function (result) {
$get('response').innerHTML = result;
});
}
</script>
</html>

|
Rich Internet Applications with PHP Mar 10, 2008 Page
Sample Application
Credits:
Stas Malyshev
Pádraic Brady

Sébastien Gruhier – Rich Window


prototype
script.aculo.us

Copyright © 2007, Zend Technologies Inc.


• High-quality PHP 5 open-
source framework
• Easy-to-use, powerful
functionality, focusing on
the best practices of robust,
secure and modern Web
applications.
• Follows principle of
“extreme simplicity,” which
makes it easy to learn and
easy to use for programmers
• Developed by members of
the PHP community, led by a
team at Zend
• Open-source process, hosted
at
framework.zend.com under
the business-friendly BSD
license
Rich Internet Applications with PHP
|
Mar 10, 2008 Page
Zend Framework Architecture

|
Rich Internet Applications with PHP Mar 10, 2008 Page
What is the MVC component?

• The heart of ZF web applications


 Model: domain-specific CONTROLLER
representation of data
 View: renders model data into
a user-interface element;
PHP-based template engine
VIEW
 Controller: processes events, MODEL
invokes changes in models
• Simple solution in most applications
 Sensible defaults are built in
 Flexible and extensible
 Supports advanced applications

|
Rich Internet Applications with PHP Mar 10, 2008 Page
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 Mar 10, 2008 Page
Chat Application
IndexController / (index)

/ (index) /name

/message

LogController / (index)

/log /log
/chat
/search

ServiceController /keyword

/flickr
/service
/amazon

|
Rich Internet Applications with PHP Mar 10, 2008 Page
Controller Actions

• Each controller action


method is responsible
for doing one specific
task
• Controller binds model
and view together

|
Rich Internet Applications with PHP Mar 10, 2008 Page
MVC entry point: index.php

<?php
$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);
// Go!
$controller->dispatch();

|
Rich Internet Applications with PHP Mar 10, 2008 Page
Model

Class ChatData
Encapsulates XML storage
Implemented as SimpleXML
Encapsulates data search
Implemented as Zend_Search_Lucene
|
Rich Internet Applications with PHP Mar 10, 2008 Page
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 Mar 10, 2008 Page
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);
}

|
Rich Internet Applications with PHP Mar 10, 2008 Page
Model: Search handling

Searching

$index = Zend_Search_Lucene::open($indexfile);
$hits = $index->find($query);
return $hits;

|
Rich Internet Applications with PHP Mar 10, 2008 Page
View

• Each action has its own


view template

• Templates rendered
automatically
 Unless the user asks not to

|
Rich Internet Applications with PHP Mar 10, 2008 Page
View – displaying search results
<? if(count($this->hits)):
$day = ""; ?>
<span class="searchterm">Looking for
'<? echo $this->query; ?>':</span><br>
<? foreach($this->hits as $message) {
$mday = date("d-M-y", $message->timestamp);
if($day != $mday) {
$day = $mday;
echo "<p class=\"day\">$day</p>"; } ?>
<p><span class="time"><?
echo date('H:i:s', $message->timestamp) ?></span>
<span class="screenname"><?
echo $message->author; ?></span>:
<span class="msgtext"><?
echo $message->text; ?></span>
</p>
<? } else: ?>
Nothing found for '<? echo $this->query; ?>', sorry.
<? endif; ?>
|
Rich Internet Applications with PHP Mar 10, 2008 Page
AJAX communication - JSON

PHP data to JSON

// This function returns JSON, not 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 Mar 10, 2008 Page
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 Mar 10, 2008 Page
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 Mar 10, 2008 Page
What’s next?
• Ajax-enabled Form component in Zend Framework
1.1
 ~Oct 2007
• Ajax support in development tools – Eclipse-based
 Javascript editing – syntax highlighting, code completion
 Javascript debugging
 Toolkit support (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 Mar 10, 2008 Page
What’s next?

• Zend Component Model


 Server:
• PHP component architecture
 Client:
• Ajax Toolkit
• Client side messaging
• Client-server connectivity
 Development tools:
• Tooling for components

|
Rich Internet Applications with PHP Mar 10, 2008 Page
Thanks!
Stanislav Malyshev [email protected]
http://devzone.zend.com/
http://framework.zend.com/

Copyright © 2007, Zend Technologies Inc.

You might also like