Getting up & running with zend framework

Post on 18-Nov-2014

1,392 views 6 download

Tags:

description

Why should we use Zend framework and how we set up the zend framework

transcript

Getting Up & Running with

Zend Framework

Agenda

• Overview

• MVC

• Components

• Environment setup

• Your first Zend Framework project

• Resources

• QA

• Toolbox

• Blueprint

• Skeleton

What is framework ?

Why Zend Framework

•Maintain by PHP Company•Open Source•Flexible Architecture • ZF Certification •Partner with

Zend Framework – Architecture

• MVC design pattern

• Front Controller pattern

• Component Based

• Loosely couple

Zend Components

Zend_Session

Zend_Validate

Zend_AuthZend_Acl

ZEND_FORM

Zend web services – Components

Z

EN

D_F

EE

D

ZE

ND

_GD

ATA

Environment Setup

• Requirements

1. PHP 5.x2. Web server with mod_rewrite enabled

Environment Setup (Continued…)

• Zend tool setup (Ubuntu way)

; include_path=${include_path} “:/path/to/libzend-framework-php” // uncomment in /etc/php5/conf.d/zend-framework.ini

sudo apt-get install zend-framework

Environment Setup (Continued…)

• Zend tool setup (Windows way)

Environment Setup (Continued…)

Environment Setup (Continued…)

Environment Setup (Continued…)

Environment Setup (Continued…)

Environment Setup (Continued…)

• Zend tool setup verification

zf show versionZend Framework Version:

1.11.10

Your first Zend Framework project

zf create project {project-name}

Your first Zend Framework project

Project structure

Create Virtual host

<VirtualHost *:80> ServerName local.sitename.comDocumentRoot /var/www/zf-project/public <Directory "/var/www/zf-project/public">

AllowOverride All </Directory>

</VirtualHost>

Tada!

Connecting to database

resources.db.adapter = "Pdo_Mysql”resources.db.params.host = ”HostName"resources.db.params.username = ”UserName"resources.db.params.password = ”Password"resources.db.params.dbname = ”DbName"

Let’s have a CRUD operation

CreateRetrieveUpdateDelete

Controller

zf create controller {name}

Controller

<?php

class AlbumController extends Zend_Controller_Action{

public function init(){ /* Initialize action controller here */

}

public function indexAction(){/* Your code goes here */

}}

Model

zf create model {model-name}

Model

<?php

class Application_Model_Albums extends Zend_Db_Table_Abstract{ protected $_name = 'albums';

public function fName() {/* Your code goes here */

}}

Crud operation

$data = array( 'artist' => $artist, 'title' => $title,);

public function addAlbum($data) {$this->insert($data);

}

public function updateAlbum($data, $where) {$this->update($data, $where);

}

public function deleteAlbum($where) {$this->delete($where);

}

$where = array('id = ?' => $id

);

Zend Frameworks Gems

1. Google2. Amazon3. Flickr4. Yahoo5. More….

• Web services

Zend web service (flickr)

Zend web service (flickr)

public function flickrAction(){ $flickr = new Zend_Service_Flickr(’YourAPIKey'); $this->view->results = $flickr->tagSearch('worldcup’);}

Zend web service (flickr)

<ul> <?php foreach ($this->results as $result){

$photo = $result->Square; ?> <li><a href="<?php echo $photo->ClickUri ?>">

<img src="<?php echo $photo->uri ?>" alt="image"/>

</a></li>

<?php } ?></ul>

Resources

• http://akrabat.com/zend-framework-tutorial/

• http://net.tutsplus.com/tutorials/php/zend-framework-from-scratch/

• http://goo.gl/fQLL6

Who we are

Shoriful Islam Ronju@leevio

Saidur Rahman Bijon@somewherein

Questions & Answers

Any Question?