• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Zend framework
 

Zend framework

on

  • 832 views

zend framework is the most used/using PHP framework today.

zend framework is the most used/using PHP framework today.
-
Regards,
Prem

Statistics

Views

Total Views
832
Views on SlideShare
832
Embed Views
0

Actions

Likes
0
Downloads
12
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Zend framework Zend framework Presentation Transcript

    • Intro• A web application framework written in PHP5• Loosely coupled set of modules that perform variousTasks‣ Database access (Zend_DB)‣ Google Data API‟s (Zend_Gdata)• Easy to implement MVC model
    • What is MVC?• MVC stands for Model-View-Controller ‣ Code is divided into three distinct groups• Model -- Internal representation of data, interface to backend storage (i.e. database), and “business logic”• View -- Code that represents the application‟s UI• Controller -- Code that generates output to populate the view using the model
    • •Download latest zend frame work•It contains two folders “bin” and “library". Copy that to wamp/bin/php/=>newfolder say zend_frame.•Change the include_path for windows in php.ini to wamp/bin/php/zend_frame/libraryNow zend is installed…to check zend is installed or not--------------- Take cmd prompt and-> type zf show version If its displaying the correct version, Your Zend is functioning
    • Take cmd => go to your local host folder here its wamp/www/Type=> zf create project Zendy projectnameYour project is created….you can check in the wwwfolder….Also copy the folder zend in the library to this project`slibrary
    • ZEND PROJECT SKELTON
    • • application/Bootstrap.php ‣ Application bootstrap code• application/configs ‣ Configuration files• application/controllers ‣ Backend controller code• application/models ‣ Code mapping from domaindata to storage data (PHP interfaceto DB for example)• application/views/scripts ‣ User interface code• application/configs/application.ini ‣ Main configuration file• application/controllers/ ‣ ErrorController.php-> Default controller called when anerror occurs ‣ IndexController.php->Default controller when nocontroller is specified
    • You can go to your project by typing localhost/zendy/public on your browser Your project frontage will be like this:
    • A controller that handles all requests for a Web site. Zend_Controller_Front implements a Front Controller pattern used in Model-View- Controller (MVC) applications. Its purpose is to initialize the request environment, route the incoming request, and then dispatch any discovered actions; it aggregates any responses and returns them when the process is complete.
    • The index.php file is the entry point to our application and is usedto create an instance of Zend_Application to initialise ourapplication and then run it. This file also defines two constants:APPLICATION_PATH and APPLICATION_ENV which define the pathto the application/ directory and the environment or mode of theapplication. The default is set to production in index.php, but youshould set it to development in the .htaccess file by adding thisline: SetEnv APPLICATION_ENV development
    • E:wampwwwzendbinapplicationviewsscriptsindex
    • Adding a New Action• When forms are submitted, there is some backendcode that processes the input‣ We will handle this in a new action within theIndexcontroller‣ We use the „zf‟ tool to create the relevant code stubs zf create action actionname controllernameEg: zf create action about index• This creates the function aboutAction() inapplication/controllers/IndexController.php class IndexController extends Zend_Controller_Action { public function addAction() { /* Initialize action controller here */ }
    • EXAMPLE FOR ZEND Page Controller Action Home page Index index Add new album Index add Edit album Index edit Delete album Index delete And the data fields are id(auto increment) ,artist and album
    • Actions zf create action add Index zf create action edit Index zf create action delete Index The URLs for each action are: http://localhost/zf-tutorial/public/ IndexController::indexAction() http://localhost/zf-tutorial/public/index/add IndexController::addAction() http://localhost/zf-tutorial/public/index/edit IndexController::editAction() http://localhost/zf-tutorial/public/index/delete IndexController::deleteAction()class IndexController extends Zend_Controller_Action { public function addAction() { /* Initialize action controller here*/ }
    • Database configurationOpen application/configs/application.ini and add the following to theend of the[production] section (i.e. above the [staging] section):resources.db.adapter = “PDO_MYSQL”resources.db.params.host = “localhost”resources.db.params.username = “root”resources.db.params.password = “”resources.db.params.dbname = “zend”
    • Create the database tableCREATE TABLE albums (id int(11) NOT NULL auto_increment,artistvarchar(100) NOT NULL,title varchar(100) NOT NULL,PRIMARY KEY(id)); Inserting test data INSERT INTO albums (artist, title) VALUES (Paolo Nutine, Sunny Side Up„), (Florence + The Machine, Lungs), (Massive Attack, Heligoland), (Andre Rieu, Forever Vienna), (Sade, Soldier of Love);
    • The MODELZend Framework provides Zend_Db_Table which implements theTable DataGateway design pattern to allow for interfacing with data in adatabase table.For this tutorial, we are going to create a model that extendsZend_Db_Table and uses Zend_Db_Table_Row. zf create db-table Albums albums <?php class Application_Model_DbTable_Albums extends Zend_Db_Table_Abstract { protected $_name = albums; } ?>
    • Layouts and viewsZend_Layout allows us to move all the common header, footer and othercode to a layout view script which then includes the specific view code forthe action being executed. Zf enable layoutZendy/application/layouts/scripts/layout.phtml To get the view script for the current action to display, we echo out the content placeholder using the layout() view helper: echo $this->layout()->content; which does the work for us.
    • We need to set the doctype for the webpage before we render any view scripts.As the action view scripts are rendered earlier and may need to know whichdoctype is in force. This is especially true for Zend_Form.To set the doctype we add another line to our application.ini, in the [production]section:resources.view.doctype = "XHTML1_STRICT“resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"The doctype() view helper will now output the correct doctype and componentslike Zend_Form willgenerate compatible HTML.
    • Styling Styling is done by making css file in ZENDY/public/css/site.css And then include that file inside the layout <?php echo $this->headLink()->prependStylesheet($this->baseUrl()./css/site.css); ?>By using headLink()‟s prependStylesheet() method, we allow for additional, more specific, CSS files to be added within the controller view scripts which will be rendered within the <head> section after site.css
    • To display all the dats in the index page…..zf-tutorial/application/controllers/IndexController.php...function indexAction(){$albums = new Application_Model_DbTable_Albums();$this->view->albums = $albums->fetchAll();}…zf-tutorial/application/views/scripts/index/index.phtml <?php foreach($this->albums as $album) : ?> <td><?php echo $this->escape($album->title);?></td> <td><?php echo $this->escape($album->artist);?></td> <a href="<?php echo $this->url(array(controller=>index, action=>edit, id=>$album->id));?>">Edit</a> <a href="<?php echo $this->url(array(controller=>index, action=>delete, id=>$album->id));?>">Delete</a> <?php endforeach; ?>
    • Adding new albums There are two bits to this part: • Display a form for user to provide details • Process the form submission and store to database zf create form AlbumThis creates the file Album.php in application/forms
    • Zend Form
    • <?phpADD action $this->title = "Add new album"; $this->headTitle($this->title) ;echo $this->form ; ?>
    • EDIT ACTION
    • zf-tutorial/application/views/scripts/index/edit.phtml<?php$this->title = "Edit album";$this->headTitle($this->title);echo $this->form ;?> DELETE ACTION
    • That‟s all………….
    • This concludes our brief look at building a simple, butfully functional, MVC application using Zend Framework.•Zend framework is loosely packed ,but more secure