Well I thought about posting this at Tutorial Dash and then realized this would be a far better place to post this.
What is the Zend Framework Really? From Zend.com
The Zend Framework community has released their 0.1.5 Preview Release. Although this is primarily a maintenance release, it does move the new RewriteRouter to the core and takes it one step closer to becoming the default routing model for the MVC portion of the framework.
The release is available on the Zend Framework website. The change log for this and prior releases can be viewed from the issue tracker.
Main Components of the Zend Framework:
Authentication & Authorization
* Zend_Acl
* Zend_Authentication
* Zend_Session
Core Infrastructure
* Zend_Cache, Zend_Config, Zend_Console, Zend_Environment, Zend_Log, Zend_Memory
* Zend_Registry, Zend_Registry_Defaults
Databases
* Zend_Db
* Zend_Db_Xml_Content
Documentation
* Improved correctness, readability, and more examples
* Additional coverage by translation teams
Internationalization (i18n) & Localization (l10n)
* Zend_Currency, Zend_Measure
* Zend_Date, Zend_Date_Calendar
* Zend_Locale
* Zend_Translate
Mail, Formats, & Search
* Zend_Filter, Zend_Filter_Input
* Zend_Json, Zend_Pdf
* Zend_Mail, Zend_Mail_Read, Zend_Mime
* Zend_Search_Lucene
Model-View-Controller (MVC)
* Zend_Controller, Zend_Controller_Action, Zend_Controller_Dispatcher, Zend_Controller_Plugin, Zend_Controller_RewriteRouter, Zend_View
* Zend_Http_Request, Zend_Http_Response
Web & Web Services
* Consuming services: Zend_Feed, Zend_Rest_Client, Zend_Service, Zend_XmlRpc_Client, Zend_GData, Zend_Http_Client
* Exposing services: Zend_Http_Server, Zend_Rest_Server, Zend_Server_Documentor, Zend_Server_Reflection, Zend_Soap_Server, Zend_XmlRpc_Server
* Zend_Uri
How would I go about using it?
From my understanding, you basically include the file, initiate the class, and bam!
There's great documentation available, and it's extremely flexible. A valuable thing to start fiddling with in my opinion.
Check it out at
http://framework.zend.com
Whats covered here?
- Web Services
- Amazon
- RSS Feeds
Still left to do?
- Web Servies
- Flickr
- Yahoo
- PDF
- Creating PDF's
- Search
- Lucene
-- Feed Search
-- Indexing
Examples
A few examples on what you can do with the Zend Framework.
Web Services
Using PHP5 and the Zend Framework to get results from Amazon, Flickr, Yahoo, and other popular things.
Amazon:
A lot of this should be self explanatory, but I can do my best to clear things up
[PHP]<?php
/**
* Query Amazon's Product Database
*/
//include the main zend file for querying amazon.
require_once 'Zend/Service/Amazon/Query.php';
$keywords = '';
$searchFor = '';
//get the keywords
if (isset($_POST) && strtolower($_SERVER) == 'post') {
if (isset($_POST)) {
$keywords = strip_tags($_POST);
}
if (isset($_POST)) {
//what to search for
$searchFor = strip_tags($_POST);
}
}
?>
<!DOCTYPE html public "-//W3C//DTD HTML 4.01//EN" "
http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<style type="text/css">
html, body {
margin: 0px;
padding: 0px;
font-family: Tahoma, Verdana, sans-serif;
font-size: 10px;
}
h1 {
margin-top: 0px;
background-color: darkblue;
color: white;
font-size: 16px;
}
form {
text-align: center;
}
label {
font-weight: bold;
}
img {
border: 0px;
padding: 5px;
}
#results {
margin-left: 30px;
}
#results .thumb {
clear: left;
float: left;
}
#results .details {
clear: right;
float: left;
}
h2 {
font-size: 14px;
color: grey;
}
h3 {
clear: both;
font-size: 12px;
}
#poweredby {
clear: both;
}
</style>
</head>
<body>
<h1>Amazon Product Search</h1>
<form action="<?php echo $_SERVER; ?>" method="post">
<p>
<label>Search For: <input type="text" name="search_term" value="<?php echo htmlspecialchars($keywords, ENT_QUOTES); ?>"></label>
<label>
in
<select name="search_type">
<?php
//an array of the different types of search methods, duh?
$search_types = array (
0 => 'Apparel',
1 => 'Baby',
2 => 'Beauty',
3 => 'Blended',
4 => 'Books',
5 => 'Classical',
6 => 'DVD',
7 => 'Digital Music',
8 => 'Electronics',
9 => 'Gourmet Food',
10 => 'Health Personal Care',
11 => 'Jewelry',
12 => 'Kitchen',
13 => 'Magazines',
14 => 'Merchants',
15 => 'Miscellaneous',
16 => 'Music',
17 => 'Music Tracks',
18 => 'Musical Instruments',
19 => 'Office Products',
20 => 'Outdoor Living',
21 => 'PC Hardware',
22 => 'Pet Supplies',
23 => 'Photo',
24 => 'Restaurants',
25 => 'Software',
26 => 'Sporting Goods',
27 => 'Tools',
28 => 'Toys',
29 => 'VHS',
30 => 'Video',
31 => 'Video Games',
32 => 'Wireless',
33 => 'Wireless Accessories',
);
foreach ($search_types as $type) {
if ($searchFor == $type) {
?>
<option value='<?php echo str_replace(" ", "", $type); ?>' selected="selected"><?php echo $type; ?></option>
<?php
} else {
?>
<option value='<?php echo str_replace(" ", "", $type); ?>'><?php echo $type; ?></option>
<?php
}
}
?>
</select>
</label>
<input type="submit" value="Search!">
</p>
</form>
<?php
//has the form been submitted?
if (strtolower($_SERVER) == 'post') {
//initiate the class.
$amazon = new Zend_Service_Amazon_Query("1338XJTNFMTHK413WFR2");
try {
//attempt to query amazon $amazon->category($searchFor)->ResponseGroup('Large')->Keywords($keywords);
//assign the results var the actual searching function.
$results = $amazon->search();
if ($results->totalResults() > 0) {
echo '<div id="results">';
echo '<h2>Search Results</h2>';
//each result formatting and crap
foreach ($results as $result) {
echo "<div>";
echo "<h3>$result->Title</h3>";
if (isset($result->MediumImage)) {
?>
<div class="thumb">
<a href='<?php echo $result->DetailPageURL; ?>' title='<?php echo $result->Title; ?>'>
<img src='<?php echo $result->MediumImage->Url->getUri(); ?>' />
</a>
</div>
<p class="details" style="height: <?php echo $result->MediumImage->Height; ?>px">
Average Rating: <?php echo $result->AverageRating; ?>
<br />
Total Reviews: <?php echo $result->TotalReviews; ?>
<br />
Price: <?php echo (isset($result->FormattedPrice)) ? $result->FormattedPrice : "Not available"; ?>
<br />
<a href='<?php echo $result->DetailPageURL; ?>'>More Details...</a>
</p>
<?php
} else {
echo "<a href='{$result->DetailPageURL}'>More Details...</a>";
}
echo "</div>";
}
echo '</div>';
}
}
catch (Zend_Service_Exception $e) {
//uh-oh! error!
echo '<p style="color: red; font-weight: bold">An error occured, please try again later. (' .$e->getMessage(). ')</p>';
}
}
?>
<p id="poweredby" style="text-align: center; font-size: 9px;">Powered by the <a href="
http://framework.zend.com">Zend Framework</a></p>
</body>
</html>[/PHP]
RSS Feeds
Working with RSS Feeds in the Zend Framework couldn't be easier!
[PHP]
<?php
/**
* Consume an RSS feed and display all of the titles and
* associated links within.
*/
require_once 'Zend/Feed.php';
//get the feed
$feed = Zend_Feed::import('
http://news.google.com/?output=rss');
//for each item, format to make pretty
foreach ($feed->items as $item) {
echo "<p>" . $item->title() . "<br />";
echo $item->link() . "</p>";
}
?>
[/PHP]
Pretty simple right? Don't think that needs any further explaination. A very very simple example though.
Pretty simple stuff, more to come soon!
(XML, PDF, Search!)
Sources:
http://framework.zend.com
http://framework.zend.com/svn/framework/trunk/
Comments
I'll re-read it a few times, thanks for this interesting article.
- xPureNLx