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/fram...
Setup
   Create config of zf script
# zf create config
Successfully written Zend Tool config.
It is located at: /usr/loca...
What is zf script
   Help info
# zf ?
Usage:
    zf [--global-opts] action-name [--action-opts] provider-name [--provider...
Create Project
   Build a project skeleton
# cd /path/to/wwwroot

# zf create project zf_test
Creating project at /path/t...
Setup Project
   Setup VirtualHost in Apache config file
<VirtualHost *:80>
   DocumentRoot "/path/to/wwwroot/zf_test/pub...
Create Protable Project
   Change position of index.php and .htaccess
# cd /path/to/wwwroot/zf_test

# cp public/.htacces...
Project Structure
   application
       configs
       controllers
       models
       views
           helpers
   ...
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
...
application.ini
   Configuration section.
# cd /path/to/wwwroot/zf_test

# vi application/configs/application.ini
[produc...
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 ident...
bootstrap in application.ini
   To load Bootstrap class.
Zend_Application_Bootstrap
   Initialize custom resources for project.
# cd /path/to/wwwroot/zf_test

# vi application/Bo...
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_Contro...
Zend_Application_Resource
   Common Resources
       Front Controller
       Router
       Database
       View
    ...
Example: Database Resource
   Initialize Custom Resources for Project
# cd /path/to/wwwroot/zf_test

# zf configure db-ad...
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.
pl...
Summary
   Zend_Application
       Load configuration.
       Set bootstrap and run.
   Zend_Application_Bootstrap
   ...
See you next part.
Upcoming SlideShare
Loading in...5
×

Head First Zend Framework - Part 1 Project & Application

5,299

Published on

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
5,299
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
52
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Transcript of "Head First Zend Framework - Part 1 Project & Application"

  1. 1. Head First Zend Framework Part 1 - Project & Application Jace Ju
  2. 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. 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. 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. 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. 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. 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. 8. Project Structure  application  configs  controllers  models  views  helpers  scripts  docs  library  public  tests
  9. 9. Application  Zend_Application  Zend_Application_Bootstrap  Zend_Application_Resource
  10. 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. 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. 12. phpSettings in application.ini  Use "ini_set" function.  See http://www.php.net/manual/en/ini.list.php.
  13. 13. includePaths in application.ini  Use "set_include_path" function.  Prepend to "include_path".  "library" is identity for configuration.
  14. 14. bootstrap in application.ini  To load Bootstrap class.
  15. 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. 16. appnamespace in application.ini  Define the autoloader prefix of models, form, etc.
  17. 17. resources in application.ini  Load common resources.  Define resource options.
  18. 18. FrontController Resource  Initialize Front Controller.  frontController.controllerdirectory  call Zend_Controller_Front::setControllerDirectory()  frontController.params  call Zend_Controller_Front::setParams()
  19. 19. Zend_Application_Resource  Common Resources  Front Controller  Router  Database  View  Session  Layout  Log  ...  More flexible then Bootstrap::_init<Resource> method.
  20. 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. 21. Autoloadernamespaces in application.ini  Register the prefix of library. Autoloadernamespaces[] = "My_"
  22. 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. 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. 24. See you next part.
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×