zend f rame w ork over vie w - ben ramsey · zend f rame w ork over vie w ben r amsey a tlanta php...
TRANSCRIPT
![Page 1: Zend F rame w ork Over vie w - Ben Ramsey · Zend F rame w ork Over vie w Ben R amsey A tlanta PHP M ay 4, 2006](https://reader034.vdocuments.us/reader034/viewer/2022042403/5f18340119c8ba34b24b3b29/html5/thumbnails/1.jpg)
Zend Framework OverviewBen RamseyAtlanta PHPMay 4, 2006
![Page 2: Zend F rame w ork Over vie w - Ben Ramsey · Zend F rame w ork Over vie w Ben R amsey A tlanta PHP M ay 4, 2006](https://reader034.vdocuments.us/reader034/viewer/2022042403/5f18340119c8ba34b24b3b29/html5/thumbnails/2.jpg)
Who am I to discuss Zend?
• I’m Ben Ramsey, and I have a blog
• Professional PHP programmer for 5 years
• Author of articles on PHP in International PHP Magazine and php|architect
• Founding Principal of the PHP Security Consortium
• PHP enthusiast and advocate
![Page 3: Zend F rame w ork Over vie w - Ben Ramsey · Zend F rame w ork Over vie w Ben R amsey A tlanta PHP M ay 4, 2006](https://reader034.vdocuments.us/reader034/viewer/2022042403/5f18340119c8ba34b24b3b29/html5/thumbnails/3.jpg)
What we will learn today
• Zend Framework background
• Framework components overview
• Zend Framework roadmap
• Setting up your environment
• A “hello, world” example
![Page 4: Zend F rame w ork Over vie w - Ben Ramsey · Zend F rame w ork Over vie w Ben R amsey A tlanta PHP M ay 4, 2006](https://reader034.vdocuments.us/reader034/viewer/2022042403/5f18340119c8ba34b24b3b29/html5/thumbnails/4.jpg)
Zend Framework background
![Page 5: Zend F rame w ork Over vie w - Ben Ramsey · Zend F rame w ork Over vie w Ben R amsey A tlanta PHP M ay 4, 2006](https://reader034.vdocuments.us/reader034/viewer/2022042403/5f18340119c8ba34b24b3b29/html5/thumbnails/5.jpg)
What is the Zend Framework?
• “Zend Framework is a high quality and open source framework for developing Web Applications and Web Services.”
• Zend’s answer to Enterprise-grade frameworks
• Zend’s tool to promote PHP use in the Enterprise
![Page 6: Zend F rame w ork Over vie w - Ben Ramsey · Zend F rame w ork Over vie w Ben R amsey A tlanta PHP M ay 4, 2006](https://reader034.vdocuments.us/reader034/viewer/2022042403/5f18340119c8ba34b24b3b29/html5/thumbnails/6.jpg)
What is the Zend Framework?
• Like PEAR, it is a collection of classes that may be used together or separately
• Designed to be free from Intellectual Property disagreements
![Page 7: Zend F rame w ork Over vie w - Ben Ramsey · Zend F rame w ork Over vie w Ben R amsey A tlanta PHP M ay 4, 2006](https://reader034.vdocuments.us/reader034/viewer/2022042403/5f18340119c8ba34b24b3b29/html5/thumbnails/7.jpg)
Project goals
• Provide a repository of high quality components that are actively supported
• Provide a complete system for developing web applications powered by PHP 5
• Don’t change PHP -- it’s already a great platform (even without a framework!)
![Page 8: Zend F rame w ork Over vie w - Ben Ramsey · Zend F rame w ork Over vie w Ben R amsey A tlanta PHP M ay 4, 2006](https://reader034.vdocuments.us/reader034/viewer/2022042403/5f18340119c8ba34b24b3b29/html5/thumbnails/8.jpg)
Project goals
• Embrace collaboration and community to further advance PHP 5 programming
• Positively contribute to the PHP 5 ecosystem and the PHP Collaboration Project
![Page 9: Zend F rame w ork Over vie w - Ben Ramsey · Zend F rame w ork Over vie w Ben R amsey A tlanta PHP M ay 4, 2006](https://reader034.vdocuments.us/reader034/viewer/2022042403/5f18340119c8ba34b24b3b29/html5/thumbnails/9.jpg)
PHP Collaboration Project
• a solid framework/development environment
• enriched development tools (Eclipse)
• best practices
![Page 10: Zend F rame w ork Over vie w - Ben Ramsey · Zend F rame w ork Over vie w Ben R amsey A tlanta PHP M ay 4, 2006](https://reader034.vdocuments.us/reader034/viewer/2022042403/5f18340119c8ba34b24b3b29/html5/thumbnails/10.jpg)
Zend Framework License
• BSD license (was originally similar to the PHP license with the “advertising clause”)
• Located here: http://framework.zend.com/license/
![Page 11: Zend F rame w ork Over vie w - Ben Ramsey · Zend F rame w ork Over vie w Ben R amsey A tlanta PHP M ay 4, 2006](https://reader034.vdocuments.us/reader034/viewer/2022042403/5f18340119c8ba34b24b3b29/html5/thumbnails/11.jpg)
More background
• There is a contribution/proposal process
• All contributors must sign the Contributor License Agreement
• There are rigid standards for writing code
• The framework is fairly easy to use
![Page 12: Zend F rame w ork Over vie w - Ben Ramsey · Zend F rame w ork Over vie w Ben R amsey A tlanta PHP M ay 4, 2006](https://reader034.vdocuments.us/reader034/viewer/2022042403/5f18340119c8ba34b24b3b29/html5/thumbnails/12.jpg)
Framework components overview
Zend_ControllerZend_DbZend_FeedZend_FilterZend_InputFilterZend_HttpClientZend_JsonZend_LogZend_Mail
Zend_MimeZend_PdfZend_SearchZend_Service_AmazonZend_Service_FlickrZend_Service_RestZend_Service_YahooZend_ViewZend_XmlRpc
![Page 13: Zend F rame w ork Over vie w - Ben Ramsey · Zend F rame w ork Over vie w Ben R amsey A tlanta PHP M ay 4, 2006](https://reader034.vdocuments.us/reader034/viewer/2022042403/5f18340119c8ba34b24b3b29/html5/thumbnails/13.jpg)
Zend Framework roadmap
• Currently seeking contributions: Zend_Auth, Zend_Acl, Zend_Feed_Builder, Zend_File, Zend_Http_Server, Zend_Locale, Zend_Session
• Stable release by Fall 2006?
• More info:http://framework.zend.com/roadmap/
![Page 14: Zend F rame w ork Over vie w - Ben Ramsey · Zend F rame w ork Over vie w Ben R amsey A tlanta PHP M ay 4, 2006](https://reader034.vdocuments.us/reader034/viewer/2022042403/5f18340119c8ba34b24b3b29/html5/thumbnails/14.jpg)
Setting up your environment
![Page 15: Zend F rame w ork Over vie w - Ben Ramsey · Zend F rame w ork Over vie w Ben R amsey A tlanta PHP M ay 4, 2006](https://reader034.vdocuments.us/reader034/viewer/2022042403/5f18340119c8ba34b24b3b29/html5/thumbnails/15.jpg)
Requirements
• PHP 5.0.4 with PDO extensions required; PHP 5.1 recommended
• Apache HTTPD server recommended for mod_rewrite rules, but not required
• Download from:http://framework.zend.com/download
![Page 16: Zend F rame w ork Over vie w - Ben Ramsey · Zend F rame w ork Over vie w Ben R amsey A tlanta PHP M ay 4, 2006](https://reader034.vdocuments.us/reader034/viewer/2022042403/5f18340119c8ba34b24b3b29/html5/thumbnails/16.jpg)
Set up your app structure• I recommend the following structure:/
application/
controllers/
views/
library/
Zend/
www/ images/
styles/
.htaccess
index.php
![Page 17: Zend F rame w ork Over vie w - Ben Ramsey · Zend F rame w ork Over vie w Ben R amsey A tlanta PHP M ay 4, 2006](https://reader034.vdocuments.us/reader034/viewer/2022042403/5f18340119c8ba34b24b3b29/html5/thumbnails/17.jpg)
Server configuration• Create an .htaccess file with the following and
place in www/
php_value include_path “../library”
RewriteEngine on
RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php
![Page 18: Zend F rame w ork Over vie w - Ben Ramsey · Zend F rame w ork Over vie w Ben R amsey A tlanta PHP M ay 4, 2006](https://reader034.vdocuments.us/reader034/viewer/2022042403/5f18340119c8ba34b24b3b29/html5/thumbnails/18.jpg)
Bootstrap file<?php
/* this file lives at www/index.php */
include 'Zend.php';
function __autoload($class)
{
Zend::loadClass($class);
}
$view = new Zend_View;
$view->addScriptPath('../application/views');
Zend::register('view', $view);
$controller = Zend_Controller_Front::getInstance()
->setControllerDirectory('../application/controllers')
->dispatch();
?>
![Page 19: Zend F rame w ork Over vie w - Ben Ramsey · Zend F rame w ork Over vie w Ben R amsey A tlanta PHP M ay 4, 2006](https://reader034.vdocuments.us/reader034/viewer/2022042403/5f18340119c8ba34b24b3b29/html5/thumbnails/19.jpg)
A “hello, world” example
![Page 20: Zend F rame w ork Over vie w - Ben Ramsey · Zend F rame w ork Over vie w Ben R amsey A tlanta PHP M ay 4, 2006](https://reader034.vdocuments.us/reader034/viewer/2022042403/5f18340119c8ba34b24b3b29/html5/thumbnails/20.jpg)
Application structure• Zend Framework applications are controlled by
instructions from the URI
• Thus, consider the following:
/
/view/#
/post/edit
/post/save
/post/remove/id/#
![Page 21: Zend F rame w ork Over vie w - Ben Ramsey · Zend F rame w ork Over vie w Ben R amsey A tlanta PHP M ay 4, 2006](https://reader034.vdocuments.us/reader034/viewer/2022042403/5f18340119c8ba34b24b3b29/html5/thumbnails/21.jpg)
Create our controller• The framework dispatcher calls the index
controller when someone access the root of the site (/), so we need to create one to handle these requests
• Create IndexController.php in application/contorllers/
![Page 22: Zend F rame w ork Over vie w - Ben Ramsey · Zend F rame w ork Over vie w Ben R amsey A tlanta PHP M ay 4, 2006](https://reader034.vdocuments.us/reader034/viewer/2022042403/5f18340119c8ba34b24b3b29/html5/thumbnails/22.jpg)
IndexController.php<?php
class IndexController extends Zend_Controller_Action
{
public function indexAction()
{
$view = Zend::registry('view');
$view->title = 'Hiya';
$view->body = 'Hello, World!';
echo $view->render('hello.php');
}
public function noRouteAction()
{
$this->_redirect('/');
}
}
?>
![Page 23: Zend F rame w ork Over vie w - Ben Ramsey · Zend F rame w ork Over vie w Ben R amsey A tlanta PHP M ay 4, 2006](https://reader034.vdocuments.us/reader034/viewer/2022042403/5f18340119c8ba34b24b3b29/html5/thumbnails/23.jpg)
Create our view• Create the following file (hello.php) and
store in application/views/
<html>
<head>
<title><?php echo $this->escape($this->title); ?></title>
</head>
<body>
<?php echo $this->escape($this->body); ?>
</body>
</html>
![Page 24: Zend F rame w ork Over vie w - Ben Ramsey · Zend F rame w ork Over vie w Ben R amsey A tlanta PHP M ay 4, 2006](https://reader034.vdocuments.us/reader034/viewer/2022042403/5f18340119c8ba34b24b3b29/html5/thumbnails/24.jpg)
Say “hello” to everyone• Now, when a user accesses http://example.org/
or http://example.org/index, they’ll see the following:<html>
<head>
<title>Hiya</title>
</head>
<body>
Hello, World!
</body>
</html>
![Page 25: Zend F rame w ork Over vie w - Ben Ramsey · Zend F rame w ork Over vie w Ben R amsey A tlanta PHP M ay 4, 2006](https://reader034.vdocuments.us/reader034/viewer/2022042403/5f18340119c8ba34b24b3b29/html5/thumbnails/25.jpg)
What have we learned?
• background on the framework
• overview of components
• quick look at the roadmap
• how to set up your environment
• said “hello” to the world
![Page 26: Zend F rame w ork Over vie w - Ben Ramsey · Zend F rame w ork Over vie w Ben R amsey A tlanta PHP M ay 4, 2006](https://reader034.vdocuments.us/reader034/viewer/2022042403/5f18340119c8ba34b24b3b29/html5/thumbnails/26.jpg)
For more information
• Zend Framework: http://framework.zend.com/
• Zend Developer Zone: http://devzone.zend.com/
• Integrate Propel: http://devzone.zend.com/node/view/id/184
• Integrate Smarty: http://devzone.zend.com/node/view/id/156
• php|arch April 06: http://phparch.com/issue.php?mid=79
• Chris Shiflett’s tutorial: http://phparch/zftut
• My blog: http://benramsey.com