SlideShare uma empresa Scribd logo
1 de 24
Baixar para ler offline
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.

Mais conteúdo relacionado

Mais procurados

Dance for the puppet master: G6 Tech Talk
Dance for the puppet master: G6 Tech TalkDance for the puppet master: G6 Tech Talk
Dance for the puppet master: G6 Tech Talk
Michael Peacock
 
Zend Framework 2 - presentation
Zend Framework 2 - presentationZend Framework 2 - presentation
Zend Framework 2 - presentation
yamcsha
 

Mais procurados (20)

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

Semelhante a Head First Zend Framework - Part 1 Project & Application

Semelhante a Head First Zend Framework - Part 1 Project & Application (20)

Zend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_ToolZend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_Tool
 
Getting up & running with zend framework
Getting up & running with zend frameworkGetting up & running with zend framework
Getting up & running with zend framework
 
Getting up and running with Zend Framework
Getting up and running with Zend FrameworkGetting up and running with Zend Framework
Getting up and running with Zend Framework
 
Introduction to Zend framework
Introduction to Zend framework Introduction to Zend framework
Introduction to Zend framework
 
Write php deploy everywhere
Write php deploy everywhereWrite php deploy everywhere
Write php deploy everywhere
 
Maven
MavenMaven
Maven
 
Maven
MavenMaven
Maven
 
Maven in Mule
Maven in MuleMaven in Mule
Maven in Mule
 
Bangpypers april-meetup-2012
Bangpypers april-meetup-2012Bangpypers april-meetup-2012
Bangpypers april-meetup-2012
 
Deployment Tactics
Deployment TacticsDeployment Tactics
Deployment Tactics
 
What makes me "Grunt"?
What makes me "Grunt"? What makes me "Grunt"?
What makes me "Grunt"?
 
CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkCodeIgniter PHP MVC Framework
CodeIgniter PHP MVC Framework
 
Improving QA on PHP projects - confoo 2011
Improving QA on PHP projects - confoo 2011Improving QA on PHP projects - confoo 2011
Improving QA on PHP projects - confoo 2011
 
Scaling up development of a modular code base
Scaling up development of a modular code baseScaling up development of a modular code base
Scaling up development of a modular code base
 
Scaling up development of a modular code base - R Munteanu
Scaling up development of a modular code base - R MunteanuScaling up development of a modular code base - R Munteanu
Scaling up development of a modular code base - R Munteanu
 
Foundations of Zend Framework
Foundations of Zend FrameworkFoundations of Zend Framework
Foundations of Zend Framework
 
Practical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails AppPractical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails App
 
Maven
MavenMaven
Maven
 
Lean Php Presentation
Lean Php PresentationLean Php Presentation
Lean Php Presentation
 
The Solar Framework for PHP 5 (2010 Confoo)
The Solar Framework for PHP 5 (2010 Confoo)The Solar Framework for PHP 5 (2010 Confoo)
The Solar Framework for PHP 5 (2010 Confoo)
 

Mais de Jace Ju (15)

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

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 

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.