2. whoami
• Matteo Magni
• @ilbonzo
• https://github.com/ilbonzo
• http://it.linkedin.com/in/matteomagni
$incontro['pugBO'][7] = 'Introduction to Zend Framework' http://magni.me
3. Zend Framework 1.X
• Zend Framework is an open source, object oriented
web application framework for PHP 5. Zend
Framework is often called a 'component library',
because it has many loosely coupled components
that you can use more or less independently.
• http://framework.zend.com/
• BSD license
• Version 1.11
$incontro['pugBO'][7] = 'Introduction to Zend Framework' http://magni.me
4. Installation
• Register and download source
• Add to your include path
– sudo mv ~/ZendFramework1.11.11/library/Zend/
/usr/share/php/Zend
OR
– sudo mv ~/ZendFramework1.11.11/library/Zend/
[project]/library/Zend
• Install bin tools
– sudo mv ~/ZendFramework1.11.11
/usr/share/php/ZendFramework
– alias
zf=/usr/share/php/ZendFramework/bin/zf.sh
$incontro['pugBO'][7] = 'Introduction to Zend Framework' http://magni.me
6. Demo project for Layar
• http://layar.com/
It's mobile browser
allows users to find
various items based
upon augmented
reality technology.
• https://github.com/ilbonzo/Wade
$incontro['pugBO'][7] = 'Introduction to Zend Framework' http://magni.me
11. ZF overview
• Models(db-
tables,objectmodels)
• Views(helpers,scripts,layouts)
• Controllers(actions,helpers)
• Forms
$incontro['pugBO'][7] = 'Introduction to Zend Framework' http://magni.me
12. Namespace & Route
• All classes named for their folder
(e.g.Application_Model_Post in
application/models/post.php)
• Every Zend module is auto loaded when
needed
• Default controller/action is Index
• URLformat: /<controller>/<action>
$incontro['pugBO'][7] = 'Introduction to Zend Framework' http://magni.me
13. Controller & Actions
$ zf create controller Point
$ zf create action view Point
$ zf create action add Point
$ zf create action update Point
$ zf create action delete Point
create file /application/controllers/PointController.php
class PointController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
// action body
}
$incontro['pugBO'][7] = 'Introduction to Zend Framework'
... http://magni.me
14. Views e Actions
• Create views
/application/views/scripts/point/[action].phtml
esempio:
<br /><br />
<div id="viewcontent">
<p>View script for controller <b>Point</b> and
script/action name <b>add</b></p>
</div>
$incontro['pugBO'][7] = 'Introduction to Zend Framework' http://magni.me
16. Zend_Db
The Zend_Db_Table solution is an implementation of the
Table Data Gateway pattern. The solution also includes a
class that implements the Row Data Gateway pattern.
$incontro['pugBO'][7] = 'Introduction to Zend Framework' http://magni.me
17. DbTable - DbTableRow
$ zf create dbtable Points points
$ zf create model Point
/application/models/Point.php
class Application_Model_Point extends Zend_Db_Table_Row_Abstract
{
function __get($key)
{
if (method_exists($this, $key)) {
return $this>$key();
}
return parent::__get($key);
}
}
$incontro['pugBO'][7] = 'Introduction to Zend Framework' http://magni.me
18. Form - Validation
$ zf create form Point
/application/forms/Point.php
class Application_Form_Point extends Zend_Form
{
public function init()
{
$title = new Zend_Form_Element_Text('title');
$title>setLabel('title')
>setRequired(true)
>addFilter('StripTags')
>addFilter('StringTrim')
>addValidator('NotEmpty');
}
}
$incontro['pugBO'][7] = 'Introduction to Zend Framework' http://magni.me
19. Controller – Form
/application/controllers/PointController.php
$form = new Application_Form_Point();
$form>submit>setLabel('Add');
$this>view>form = $form;
if ($this>getRequest()>isPost()) {
$formData = $this>getRequest()>getPost();
if ($form>isValid($formData)) {
$title = $form>getValue('title');
....
$point = new Application_Model_DbTable_Points();
$point>addPoint($title, $footnote, $description, $lat, $lon,
$alt);
$this>_helper>redirector('index');
} else {
$form>populate($formData);
}
}
$incontro['pugBO'][7] = 'Introduction to Zend Framework' http://magni.me
20. Views - Form
/application/views/scripts/point/add.phtml
<?php
$this>title = "Add new Point";
$this>headTitle($this>title);
echo $this>form ;
?>
$incontro['pugBO'][7] = 'Introduction to Zend Framework' http://magni.me