SlideShare a Scribd company logo
Head First Zend Framework
       Part 1 - Project & Application

                               Jace Ju
Install
   Get Zend Framework from svn repository.
# cd /path/to/library/php

# svn co http://framework.zend.com/svn/framework/standard/tags/release-
1.10.x/library/Zend

(add ZF_HOME = /path/to/ZF, example: /usr/local/ZF)

# cd $ZF_HOME

# svn co http://framework.zend.com/svn/framework/standard/tags/release-1.10.x/bin

# cd bin

# ln –s $ZF_HOME/bin/zf.sh $ZF_HOME/bin/zf
Setup
   Create config of zf script
# zf create config
Successfully written Zend Tool config.
It is located at: /usr/local/ZF/.zf.ini

(Bug in ZF 1.10.6.)
# vi /usr/local/ZF/.zf.ini
php.includepath change to php.include_path

# zf show config
User Configuration: /usr/local/ZF/.zf.ini
  `-- php
      `-- include_path: /usr/local/lib/php:/var/lib/php:.
What is zf script
   Help info
# zf ?
Usage:
    zf [--global-opts] action-name [--action-opts] provider-name [--provider-opts]
[provider parameters ...]
    Note: You may use "?" in any place of the above usage string to ask for more
specific help information.
    Example: "zf ? version" will list all available actions for the version provider.

... (ignore) ...

DbTable
    zf create db-table name actual-table-name module force-overwrite
    Note: There are specialties, use zf create db-table.? to get specific help on
them.

    ProjectProvider
      zf create project-provider name actions
Create Project
   Build a project skeleton
# cd /path/to/wwwroot

# zf create project zf_test
Creating project at /path/to/wwwroot/zf_test
Note: This command created a web project, for more information setting up your VHOST,
please see docs/README

# cd /path/to/wwwroot/zf_test

# zf show project.info
Working with project located at: /path/to/wwwroot/zf_test

# zf show profile
ProjectDirectory
    ProjectProfileFile
    ... (ignore) ...
    TestsDirectory
        TestPHPUnitConfigFile
        TestApplicationDirectory
            TestApplicationBootstrapFile
        TestLibraryDirectory
            TestLibraryBootstrapFile
Setup Project
   Setup VirtualHost in Apache config file
<VirtualHost *:80>
   DocumentRoot "/path/to/wwwroot/zf_test/public"
   ServerName zf_test

    # This should be omitted in the production environment
    SetEnv APPLICATION_ENV development

    <Directory "/path/to/wwwroot/zf_test/public">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>

</VirtualHost>



   http://zf_test/
Create Protable Project
   Change position of index.php and .htaccess
# cd /path/to/wwwroot/zf_test

# cp public/.htaccess .

# cp public/index.php .

# vi public/.htaccess
RewriteEngine Off

# vi public/index.php
<?php
header('HTTP/1.1 403 Forbidden');

# vi .htaccess
SetEnv APPLICATION_ENV development

# vi index.php
'/../application' change to '/application'



   http://localhost/zf_test/
Project Structure
   application
       configs
       controllers
       models
       views
           helpers
           scripts
   docs
   library
   public
   tests
Application
   Zend_Application
   Zend_Application_Bootstrap
   Zend_Application_Resource
Zend_Application
   Load Configuration.
   Initialize bootstrap.
   Run.
# cd /path/to/wwwroot/zf_test

# vi index.php
... (ignore) ...

// Create application, bootstrap, and run
$application = new Zend_Application(
    APPLICATION_ENV,
    APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()
            ->run();
application.ini
   Configuration section.
# cd /path/to/wwwroot/zf_test

# vi application/configs/application.ini
[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0

[staging : production]

[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1
phpSettings in application.ini
   Use "ini_set" function.
   See http://www.php.net/manual/en/ini.list.php.
includePaths in application.ini
   Use "set_include_path" function.
   Prepend to "include_path".
   "library" is identity for configuration.
bootstrap in application.ini
   To load Bootstrap class.
Zend_Application_Bootstrap
   Initialize custom resources for project.
# cd /path/to/wwwroot/zf_test

# vi application/Bootstrap.php
<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    protected function _initResource1()
    {
        $this->bootstrap('resource2'); // Initialize Resource 2 first.
        echo "Initialize Resource 1n";
    }

     protected function _initResource2()
     {
         echo "Initialize Resource 2n ";
     }
}
appnamespace in application.ini
   Define the autoloader prefix of models, form,
    etc.
resources in application.ini
   Load common resources.
   Define resource options.
FrontController Resource
   Initialize Front Controller.
   frontController.controllerdirectory
       call Zend_Controller_Front::setControllerDirectory()
   frontController.params
       call Zend_Controller_Front::setParams()
Zend_Application_Resource
   Common Resources
       Front Controller
       Router
       Database
       View
       Session
       Layout
       Log
       ...
   More flexible then Bootstrap::_init<Resource>
    method.
Example: Database Resource
   Initialize Custom Resources for Project
# cd /path/to/wwwroot/zf_test

# zf configure db-adapter "adapter=mysqli&username=uname&password=mypass&dbname=mydb"
A db configuration for the production section has been written to the application
config file.

# vi application/configs/application.ini
[production]
... (ignore) ...
resources.db.adapter = "mysqli"
resources.db.params.username = "uname"
resources.db.params.password = "mypass"
resources.db.params.dbname = "mydb"

... (ignore) ...




   Will initialize Zend_Application_Resource_Db
Autoloadernamespaces in application.ini
   Register the prefix of library.
Autoloadernamespaces[] = "My_"
pluginPaths in application.ini
   Register the prefix and path of plugin classes.
   Resolve loading order of plugin.
pluginPaths.My_Application_Resource_ = "My/Application/Resource"
Summary
   Zend_Application
       Load configuration.
       Set bootstrap and run.
   Zend_Application_Bootstrap
       Initialize resources.
   Zend_Application_Resource
       Get options from configuration.
       Initialize controller, view, database, etc.
See you next part.

More Related Content

PPTX
Zend framework
PPT
Zend - Installation And Sample Project Creation
PDF
What happens in laravel 4 bootstraping
PDF
Codeigniter : Two Step View - Concept Implementation
KEY
Php Unit With Zend Framework Zendcon09
PDF
Unit testing after Zend Framework 1.8
PPT
Zend Framework 1.8 Features Webinar
PDF
Extending the WordPress REST API - Josh Pollock
Zend framework
Zend - Installation And Sample Project Creation
What happens in laravel 4 bootstraping
Codeigniter : Two Step View - Concept Implementation
Php Unit With Zend Framework Zendcon09
Unit testing after Zend Framework 1.8
Zend Framework 1.8 Features Webinar
Extending the WordPress REST API - Josh Pollock

What's hot (20)

PDF
Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...
PDF
Connecting Content Silos: One CMS, Many Sites With The WordPress REST API
PDF
Using the new WordPress REST API
PDF
Introduction to AngularJS For WordPress Developers
PDF
Codeigniter : Using Third Party Components - Zend Framework Components
KEY
CodeIgniter 3.0
PPTX
Reusable bootstrap resources zend con 2010
PDF
Caldera Learn - LoopConf WP API + Angular FTW Workshop
PDF
Phinx talk
PDF
Kyiv.py #17 Flask talk
PPT
Dance for the puppet master: G6 Tech Talk
ODP
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
PDF
Rest api with Python
PDF
Zend Framework 2 - presentation
PDF
ACL in CodeIgniter
PDF
ZF2 for the ZF1 Developer
PDF
Silex Cheat Sheet
PDF
Complex Sites with Silex
PDF
Best Practices in Plugin Development (WordCamp Seattle)
PPTX
Migrate yourself. code -> module -> mind
Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...
Connecting Content Silos: One CMS, Many Sites With The WordPress REST API
Using the new WordPress REST API
Introduction to AngularJS For WordPress Developers
Codeigniter : Using Third Party Components - Zend Framework Components
CodeIgniter 3.0
Reusable bootstrap resources zend con 2010
Caldera Learn - LoopConf WP API + Angular FTW Workshop
Phinx talk
Kyiv.py #17 Flask talk
Dance for the puppet master: G6 Tech Talk
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Rest api with Python
Zend Framework 2 - presentation
ACL in CodeIgniter
ZF2 for the ZF1 Developer
Silex Cheat Sheet
Complex Sites with Silex
Best Practices in Plugin Development (WordCamp Seattle)
Migrate yourself. code -> module -> mind
Ad

Similar to Head First Zend Framework - Part 1 Project & Application (20)

PDF
Getting started-with-zend-framework
PDF
Getting started-with-zend-framework
PDF
Building Web Applications with Zend Framework
PPT
Edp bootstrapping a-software_company
PPTX
Getting up & running with zend framework
PPTX
Getting up and running with Zend Framework
PDF
Zend Framework Quick Start Walkthrough
PPTX
Web application development using zend framework
KEY
Zend framework: Getting to grips (ZF1)
PDF
Zend Framework 1.8 workshop
PPT
Getting Started with Zend Framework
KEY
Webinar: Zend framework Getting to grips (ZF1)
PDF
Quick start on Zend Framework 2
ODP
Zero to Zend Framework in 10 minutes
KEY
Extending ZF & Extending With ZF
PDF
Zend Framework 2, What's new, Confoo 2011
PDF
Introduction to Zend framework
PDF
Best Practices in PHP Application Deployment
Getting started-with-zend-framework
Getting started-with-zend-framework
Building Web Applications with Zend Framework
Edp bootstrapping a-software_company
Getting up & running with zend framework
Getting up and running with Zend Framework
Zend Framework Quick Start Walkthrough
Web application development using zend framework
Zend framework: Getting to grips (ZF1)
Zend Framework 1.8 workshop
Getting Started with Zend Framework
Webinar: Zend framework Getting to grips (ZF1)
Quick start on Zend Framework 2
Zero to Zend Framework in 10 minutes
Extending ZF & Extending With ZF
Zend Framework 2, What's new, Confoo 2011
Introduction to Zend framework
Best Practices in PHP Application Deployment
Ad

More from Jace Ju (15)

PDF
Advanced php testing in action
PDF
Beginning PHPUnit
PDF
深入淺出 MVC
PPTX
如何打造 WebMVC Framework - 基礎概念篇
PDF
Refactoring with Patterns in PHP
PDF
Patterns in Library Design (套件設計裡的模式)
PDF
購物車程式架構簡介
PDF
Patterns in Zend Framework
PDF
常見設計模式介紹
PDF
PHPUnit 入門介紹
PDF
Web Refactoring
PDF
jQuery 實戰經驗講座
PDF
CSS 排版 - 基礎觀念篇
PDF
PHP 防駭 - 基礎觀念篇
PDF
PHP 物件導向 - 基礎觀念篇
Advanced php testing in action
Beginning PHPUnit
深入淺出 MVC
如何打造 WebMVC Framework - 基礎概念篇
Refactoring with Patterns in PHP
Patterns in Library Design (套件設計裡的模式)
購物車程式架構簡介
Patterns in Zend Framework
常見設計模式介紹
PHPUnit 入門介紹
Web Refactoring
jQuery 實戰經驗講座
CSS 排版 - 基礎觀念篇
PHP 防駭 - 基礎觀念篇
PHP 物件導向 - 基礎觀念篇

Recently uploaded (20)

PPTX
sap open course for s4hana steps from ECC to s4
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
MYSQL Presentation for SQL database connectivity
PDF
cuic standard and advanced reporting.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Machine learning based COVID-19 study performance prediction
PDF
Encapsulation theory and applications.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Big Data Technologies - Introduction.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Empathic Computing: Creating Shared Understanding
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Electronic commerce courselecture one. Pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
sap open course for s4hana steps from ECC to s4
Chapter 3 Spatial Domain Image Processing.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
MYSQL Presentation for SQL database connectivity
cuic standard and advanced reporting.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Machine learning based COVID-19 study performance prediction
Encapsulation theory and applications.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
“AI and Expert System Decision Support & Business Intelligence Systems”
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
The AUB Centre for AI in Media Proposal.docx
Big Data Technologies - Introduction.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Spectral efficient network and resource selection model in 5G networks
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Empathic Computing: Creating Shared Understanding
Advanced methodologies resolving dimensionality complications for autism neur...
Electronic commerce courselecture one. Pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx

Head First Zend Framework - Part 1 Project & Application

  • 1. Head First Zend Framework Part 1 - Project & Application Jace Ju
  • 2. Install  Get Zend Framework from svn repository. # cd /path/to/library/php # svn co http://framework.zend.com/svn/framework/standard/tags/release- 1.10.x/library/Zend (add ZF_HOME = /path/to/ZF, example: /usr/local/ZF) # cd $ZF_HOME # svn co http://framework.zend.com/svn/framework/standard/tags/release-1.10.x/bin # cd bin # ln –s $ZF_HOME/bin/zf.sh $ZF_HOME/bin/zf
  • 3. Setup  Create config of zf script # zf create config Successfully written Zend Tool config. It is located at: /usr/local/ZF/.zf.ini (Bug in ZF 1.10.6.) # vi /usr/local/ZF/.zf.ini php.includepath change to php.include_path # zf show config User Configuration: /usr/local/ZF/.zf.ini `-- php `-- include_path: /usr/local/lib/php:/var/lib/php:.
  • 4. What is zf script  Help info # zf ? Usage: zf [--global-opts] action-name [--action-opts] provider-name [--provider-opts] [provider parameters ...] Note: You may use "?" in any place of the above usage string to ask for more specific help information. Example: "zf ? version" will list all available actions for the version provider. ... (ignore) ... DbTable zf create db-table name actual-table-name module force-overwrite Note: There are specialties, use zf create db-table.? to get specific help on them. ProjectProvider zf create project-provider name actions
  • 5. Create Project  Build a project skeleton # cd /path/to/wwwroot # zf create project zf_test Creating project at /path/to/wwwroot/zf_test Note: This command created a web project, for more information setting up your VHOST, please see docs/README # cd /path/to/wwwroot/zf_test # zf show project.info Working with project located at: /path/to/wwwroot/zf_test # zf show profile ProjectDirectory ProjectProfileFile ... (ignore) ... TestsDirectory TestPHPUnitConfigFile TestApplicationDirectory TestApplicationBootstrapFile TestLibraryDirectory TestLibraryBootstrapFile
  • 6. Setup Project  Setup VirtualHost in Apache config file <VirtualHost *:80> DocumentRoot "/path/to/wwwroot/zf_test/public" ServerName zf_test # This should be omitted in the production environment SetEnv APPLICATION_ENV development <Directory "/path/to/wwwroot/zf_test/public"> Options Indexes MultiViews FollowSymLinks AllowOverride All Order allow,deny Allow from all </Directory> </VirtualHost>  http://zf_test/
  • 7. Create Protable Project  Change position of index.php and .htaccess # cd /path/to/wwwroot/zf_test # cp public/.htaccess . # cp public/index.php . # vi public/.htaccess RewriteEngine Off # vi public/index.php <?php header('HTTP/1.1 403 Forbidden'); # vi .htaccess SetEnv APPLICATION_ENV development # vi index.php '/../application' change to '/application'  http://localhost/zf_test/
  • 8. Project Structure  application  configs  controllers  models  views  helpers  scripts  docs  library  public  tests
  • 9. Application  Zend_Application  Zend_Application_Bootstrap  Zend_Application_Resource
  • 10. Zend_Application  Load Configuration.  Initialize bootstrap.  Run. # cd /path/to/wwwroot/zf_test # vi index.php ... (ignore) ... // Create application, bootstrap, and run $application = new Zend_Application( APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini' ); $application->bootstrap() ->run();
  • 11. application.ini  Configuration section. # cd /path/to/wwwroot/zf_test # vi application/configs/application.ini [production] phpSettings.display_startup_errors = 0 phpSettings.display_errors = 0 includePaths.library = APPLICATION_PATH "/../library" bootstrap.path = APPLICATION_PATH "/Bootstrap.php" bootstrap.class = "Bootstrap" appnamespace = "Application" resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers" resources.frontController.params.displayExceptions = 0 [staging : production] [testing : production] phpSettings.display_startup_errors = 1 phpSettings.display_errors = 1 [development : production] phpSettings.display_startup_errors = 1 phpSettings.display_errors = 1 resources.frontController.params.displayExceptions = 1
  • 12. phpSettings in application.ini  Use "ini_set" function.  See http://www.php.net/manual/en/ini.list.php.
  • 13. includePaths in application.ini  Use "set_include_path" function.  Prepend to "include_path".  "library" is identity for configuration.
  • 14. bootstrap in application.ini  To load Bootstrap class.
  • 15. Zend_Application_Bootstrap  Initialize custom resources for project. # cd /path/to/wwwroot/zf_test # vi application/Bootstrap.php <?php class Bootstrap extends Zend_Application_Bootstrap_Bootstrap { protected function _initResource1() { $this->bootstrap('resource2'); // Initialize Resource 2 first. echo "Initialize Resource 1n"; } protected function _initResource2() { echo "Initialize Resource 2n "; } }
  • 16. appnamespace in application.ini  Define the autoloader prefix of models, form, etc.
  • 17. resources in application.ini  Load common resources.  Define resource options.
  • 18. FrontController Resource  Initialize Front Controller.  frontController.controllerdirectory  call Zend_Controller_Front::setControllerDirectory()  frontController.params  call Zend_Controller_Front::setParams()
  • 19. Zend_Application_Resource  Common Resources  Front Controller  Router  Database  View  Session  Layout  Log  ...  More flexible then Bootstrap::_init<Resource> method.
  • 20. Example: Database Resource  Initialize Custom Resources for Project # cd /path/to/wwwroot/zf_test # zf configure db-adapter "adapter=mysqli&username=uname&password=mypass&dbname=mydb" A db configuration for the production section has been written to the application config file. # vi application/configs/application.ini [production] ... (ignore) ... resources.db.adapter = "mysqli" resources.db.params.username = "uname" resources.db.params.password = "mypass" resources.db.params.dbname = "mydb" ... (ignore) ...  Will initialize Zend_Application_Resource_Db
  • 21. Autoloadernamespaces in application.ini  Register the prefix of library. Autoloadernamespaces[] = "My_"
  • 22. pluginPaths in application.ini  Register the prefix and path of plugin classes.  Resolve loading order of plugin. pluginPaths.My_Application_Resource_ = "My/Application/Resource"
  • 23. Summary  Zend_Application  Load configuration.  Set bootstrap and run.  Zend_Application_Bootstrap  Initialize resources.  Zend_Application_Resource  Get options from configuration.  Initialize controller, view, database, etc.
  • 24. See you next part.