SlideShare a Scribd company logo
“From Zero to ZF” on IBM i
Your first Zend Framework project




         Alan Seiden Consulting
         alanseiden.com
My focus

   Advancing PHP on IBM i

   • PHP project leader, Zend/IBM Toolkit
   • Contributor, Zend Framework DB2/i enhancements
   • Developer, Best Web Solution, IBM/Common
   • Authority, subsecond web performance
       on IBM i/iSeries



Alan Seiden Consulting    2      From Zero to ZF on IBM i: Your first Zend Framework project
Contact information

   Alan Seiden
   alan@alanseiden.com
   201-447-2437


   alanseiden.com
   twitter: @alanseiden

Alan Seiden Consulting   3   From Zero to ZF on IBM i: Your first Zend Framework project
Where to download these slides


       From my site
       http://alanseiden.com/presentations

       On SlideShare
       http://slideshare.net/aseiden

       The latest version will be available on both sites




Alan Seiden Consulting             4         From Zero to ZF on IBM i: Your first Zend Framework project
Whom this talk is for

    • Experienced PHP developers…
             …will see a step-by-step demonstration of how to create a
              Zend Framework project that runs on the first try

    • Zend Framework developers…
             …will learn a streamlined, methodical approach that uses
              today’s tools


    • Others…
             …will maybe see something interesting.
              To beginning PHP developers: Regular PHP is fine. You will
              know when the time is right to jump in with ZF.




Alan Seiden Consulting                  5           From Zero to ZF on IBM i: Your first Zend Framework project
What we’ll do today

    • Help you get a feeling of SUCCESS
          with Zend Framework (v1.x) on IBM i

    • We’ll get you past common sticking points:
                Installing ZF
                Creating a remote project (IFS-based) in Zend Studio
                Apache web server configuration, including “rewrite” rules
                Adding to the default project
                Getting library lists to work (and other db2 on i options, too)


    • I’ll provide additional resources for study
    • And answer your questions
Alan Seiden Consulting                       6            From Zero to ZF on IBM i: Your first Zend Framework project
ZF Basics
What ZF is

   • PHP-based framework with
      best practices for PHP5, OO

   • Free and open source

   • Cross-platform

   • Developed by the community and full-time,
      dedicated Zend employees, with help from other
      important technology companies

   • Downloaded millions of times
Alan Seiden Consulting        8        From Zero to ZF on IBM i: Your first Zend Framework project
A component library AND a full framework

   • ZF includes popular individual components for mail,
      security, forms, PDF, web services, and much more.
          These components can be used from “regular” PHP
          They are the “gateway drug” of ZF


   • As a full stack framework, ZF includes a Model-View-
      Controller (MVC) architecture that makes apps easy
      to maintain




Alan Seiden Consulting               9          From Zero to ZF on IBM i: Your first Zend Framework project
Friendly URLs

   • ZF supports friendly URLs by default

    • URLs route to PHP script and function/method
            Defined by ZF’s router
            URL split into script/method/variables according to naming
             convention (controller and action)

    • Example: http://mysite.com/customer/list/division/2

    • In example above:
            Script: CustomerController.php
            Method/function: listAction()
            division = 2

Alan Seiden Consulting                  10           From Zero to ZF on IBM i: Your first Zend Framework project
MVC directory structure: more than MVC

   • Model, View, Controller folders, of course
   • “Public” folder, which is the only public folder
          Consistent with best security practices
          Public script index.php initiates a “Front controller”
   • Other resources such as configuration files, layouts,
      code libraries and documentation




Alan Seiden Consulting                   11            From Zero to ZF on IBM i: Your first Zend Framework project
How ZF fits with Zend’s product line

   • Zend Server http://www.zend.com/en/products/server/
          A value-added PHP install for IBM i, Linux, Windows, Mac OS X
          As “free” Community Edition (CE) and regular edition
          Installs a copy of Zend Framework


   • Zend Studio http://www.zend.com/en/products/studio/
          Integrated Development Environment (IDE)
          IBM i edition is “free” thanks to IBM/Zend relationship
          Also installs its own copy of Zend Framework! (on your PC)

   • Zend Framework http://framework.zend.com
          Can work with any PHP 5.x install, anywhere, but of course it
           works very well with the above products

Alan Seiden Consulting                 12           From Zero to ZF on IBM i: Your first Zend Framework project
Installing ZF
It’s already there--or download fresh

   • Installed automatically with Zend Server
      /usr/local/zendsvr/share/ZendFramework/library/zend

   • Updates available at http://framework.zend.com/download/
      latest
          Unzip into /usr/local… (see above) or your ZF library folder


   • PEAR channel on Google Code
          Instructions: http://engineeredweb.com/blog/10/6/
           installing-and-using-zend-framework-pear


   • More ideas: http://mikepavlak.blogspot.com/2010/09/
      updating-zend-framework-on-ibm-i.html



Alan Seiden Consulting                      14            From Zero to ZF on IBM i: Your first Zend Framework project
Zend Server’s easy default install

   • This way is fine when you are starting out

   • Folder is /usr/local/zendsvr/share/ZendFramework/
          Contains library/zend

   • PHP.INI specifies “/usr/local/zendsvr/share/
      ZendFramework/” in its include_path variable
          All your PHP applications will be able to find the library/
           zend folder without any further work




Alan Seiden Consulting                       15             From Zero to ZF on IBM i: Your first Zend Framework project
Step-by-step ZF
    project
Step by step ZF configuration
    • Set up SSH
           (server) on IBM i
           (client) in Zend Studio
    • Create project directory on remote server (IBM i)
    • Use Zend_Tool to generate skeleton project
           We’ll use Zend Studio’s Zend_Tool integration rather than
            PASE’s zf.sh script, though both work
    • Configure Apache webserver virtual host
    • Test basic project. It should run at this point
    • Configure DB2 adapter for IBM i and test db table
    • Create additional controller/action
Alan Seiden Consulting                  17           From Zero to ZF on IBM i: Your first Zend Framework project
SSH setup
SSH = Secure Shell protocol

   • Faster and more secure than FTP
   • Zend Studio connects over SSH to the IBM i
          SSH server (daemon) is IBM i
          SSH client is Zend Studio


   • Let’s see how to set up the server and client




Alan Seiden Consulting                19   From Zero to ZF on IBM i: Your first Zend Framework project
Starting SSH daemon (sshd) on IBM i

      • i6.1 or higher: one step creates keys and starts server
      STRTCPSVR *SSHD


      • V5R4: two steps
      First, create public/private key pairs:
      CALL QP2TERM
      ssh-keygen -t rsa1 -f /QOpenSys/QIBM/UserData/SC1/OpenSSH/
        openssh-3.5p1/etc/ssh_host_key -N ""
      ssh-keygen -t dsa -f /QOpenSys/QIBM/UserData/SC1/OpenSSH/
        openssh-3.5p1/etc/ssh_host_dsa_key -N ""
      ssh-keygen -t rsa -f /QOpenSys/QIBM/UserData/SC1/OpenSSH/
        openssh-3.5p1/etc/ssh_host_rsa_key -N "
                                                              For more on sshd setup, see
                                                              “Young i Professionals” wiki:
      Then start sshd (“&” means to run in background):
      /usr/sbin/sshd &
                                                              http://174.79.32.155/wiki/
                                                              index.php/PASE/SSHSetup

Alan Seiden Consulting                          20        From Zero to ZF on IBM i: Your first Zend Framework project
Zend Studio as an SSH client

      • Open the Remote Systems perspective
             (Window / Perspective / Remote Systems)
      • Click the “Define a connection…” button




Alan Seiden Consulting                 21          From Zero to ZF on IBM i: Your first Zend Framework project
Define connection to IBM i
 1. Choose SSH as connection type. Click “Next.”
 2. Provide host name (IP or domain name) of your “i”. Click “Finish.”




Alan Seiden Consulting           22          From Zero to ZF on IBM i: Your first Zend Framework project
Done! We’re connected to IBM i
 1. On left: Remote System Explorer, an IFS file list
 2. On right: Remote Shell, handy for entering shell commands
      (List of shell commands: http://ss64.com/bash)




Alan Seiden Consulting                      23         From Zero to ZF on IBM i: Your first Zend Framework project
Create project
  directory
Create IFS directory for project
 •    Typical directory pattern: /www/anything/htdocs
       • Example: /www/zfdemo/htdocs

 •    From 5250 screen, use “md” command for each dir level



 •    Or, better, use “mkdir” from PASE or Remote Shell in Zend Studio
      For example: “mkdir –p /www/zfdemo/htdocs”




  •     “-p” means “create parent folders if necessary”
  •     Verify it was created: WRKLNK or “ls /www/zfdemo/htdocs”



Alan Seiden Consulting                25           From Zero to ZF on IBM i: Your first Zend Framework project
Create project with
    Zend_Tool
Zend_Tool creates ZF files/folders for us
 •    It’s a component that sets up our project correctly and quickly

 •    Command-line interface: “zf” (lower case)
        •     UNIX or PASE: a shell script called zf.sh
        •     Zend Studio: use the “Zend Tool” menu option from the Project menu
                •        Keyboard shortcut: CTRL+2

 •    Another Studio interface to Zend_Tool is the “New…” wizard from
      the File menu
        •     Underneath, it calls the “zf” commands, so you might want to try it to learn
              the “zf” commands better

 •    Here we will use the “Zend Tool”option from Project menu
       • Make sure you clicked on the “PHP Explorer” pane first
       • zf command line looks like:



Alan Seiden Consulting                               27     From Zero to ZF on IBM i: Your first Zend Framework project
Launch Zend Tool command entry

   • Click on the PHP Explorer pane
   • Click Project, then Zend Tool
          Shortcut: CTRL+2




Alan Seiden Consulting        28      From Zero to ZF on IBM i: Your first Zend Framework project
Create the project

  • Let’s name the project “zfdemo”
         Will fit nicely with the folder we created, /www/zfdemo/htdocs
  • Type these commands into Zend Tool window:
         Go to Studio’s workspace root: “cd /”
         Create the project: “zf create project zfdemo”




   • Press F5 or File/Refresh to refresh view of files

Alan Seiden Consulting                  29           From Zero to ZF on IBM i: Your first Zend Framework project
Our project is there

  • You should see a complete project structure called
     zfdemo


                             IndexController: default controller
                             indexAction:    default action within
                                             a controller
                             “index” is a default name
                             (Compare index.html as the usual
                             homepage of a website)

   • The project exists in Studio’s workspace
   • Now we should link it to IFS for automatic
      synchronization

Alan Seiden Consulting       30            From Zero to ZF on IBM i: Your first Zend Framework project
Enable remote synch of project with IFS

  • Right-click the project
  • Choose “properties,” then “Remote Server Support”




Alan Seiden Consulting     31       From Zero to ZF on IBM i: Your first Zend Framework project
Set up the Remote Support settings

  • Click “Enable remote connection properties”
  • Choose the remote connection you created earlier
  • Type the Project Directory you created earlier
         Example: /www/zfdemo/htdocs
  • Leave “On Save” as upload method; click OK




Alan Seiden Consulting                  32   From Zero to ZF on IBM i: Your first Zend Framework project
Upload the project to IFS

  • You’ll be asked: “Do you want to upload all files to
     the remote server?”
         Click “Yes” then “Finish”




   • Project is now on IFS


Alan Seiden Consulting                33   From Zero to ZF on IBM i: Your first Zend Framework project
Project files are now on IFS

   • Verify with Remote Systems Explorer (use F5)
   • or WRKLNK ‘/www/zfdemo’




Alan Seiden Consulting      34        From Zero to ZF on IBM i: Your first Zend Framework project
Configure Apache
Control access/routing to our project
 •    The folder called “public”is Document Root, containing index.php




 •    Use Apache “rewrite rules” to route all ZF requests to index.php

 •    ZF’s router will examine the original REQUEST_URI to route
      request to correct controller and action




Alan Seiden Consulting             36          From Zero to ZF on IBM i: Your first Zend Framework project
More about Apache config

 • For performance and security, do not use .htaccess
   files in production systems

 • Put configurations in main httpd.conf instead

 • See example of correct virtual host config on next
   slide…




Alan Seiden Consulting      37       From Zero to ZF on IBM i: Your first Zend Framework project
Section from /www/zendsvr/conf/
httpd.conf
        # use your choice of IP and port, if they are not already in use elsewhere
        # Use 80 for a public site and 443 for SSL-encrypted
        Listen *:12345
        # NameVirtualHost allows us to share an IP address/port among multiple sites
        NameVirtualHost *:12345
        <VirtualHost *:12345>
            DocumentRoot "/www/zfdemo/htdocs/public"

              # specify ServerName if using NameVirtualHost (must match URL typed in browser)
              ServerName 1.2.3.4:12345

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

             #Detailed documentation: http://framework.zend.com/manual/en/project-structure.rewrite.html
             RewriteEngine off
             <Location />
                 RewriteEngine On
                 RewriteCond %{REQUEST_FILENAME} -s [OR]
                 RewriteCond %{REQUEST_FILENAME} -l [OR]
                 RewriteCond %{REQUEST_FILENAME} -d
                 RewriteRule ^.*$ - [NC,L]
                 RewriteRule ^.*$ /index.php [NC,L]
             </Location>
            <Directory "/www/zfdemo/htdocs/public">
                Options Indexes MultiViews FollowSymLinks
                AllowOverride None
                Order allow,deny
                Allow from all
            </Directory>

        </VirtualHost>




Alan Seiden Consulting                                 38                 From Zero to ZF on IBM i: Your first Zend Framework project
Update Apache conf and then restart
 •    Update /www/zendsvr/conf/httpd.conf with a config for your ZF project
       • Previous slide contains a solid template for you

 •    Restart Apache
      STRTCPSVR SERVER(*HTTP) RESTART(*HTTP) HTTPSVR(ZENDSVR)

 •    The sample project should run!
       • http://yourserver:port




Alan Seiden Consulting                 39          From Zero to ZF on IBM i: Your first Zend Framework project
Create more
controllers/actions
Zend_Tool continues to help

   • Let’s create a Customer controller
   • And then an action to show a list of customers
          Call it “list”
   • Once again, launch Studio’s Zend_Tool window
   • Create the Customer controller:
   cd /zfdemo
   zf create controller Customer

   • Press F5 to refresh, then create the ‘list’ action:
   zf create action list Customer
   • Refresh again (F5)

Alan Seiden Consulting         41         From Zero to ZF on IBM i: Your first Zend Framework project
Our new controller and action are there




    If you open the CustomerController.php file you will find:
    public function listAction()
    {
    }


Alan Seiden Consulting                42           From Zero to ZF on IBM i: Your first Zend Framework project
Configure DB2
Configure Zend_Db adapter for Db2

   At a minimum, create these settings:
   •   adapter type (Db2)
   •   username (may be blank)
   •   password (may be blank)
   •   dbname (may be blank or an entry from WRKRDBDIRE)


   Run: zf    configure db-adapter
       "adapter=Db2&username=alan&password=secretpw&dbname=*LOCAL"


   The above zf command creates four keys in application.ini:
   resources.db.adapter = Db2
   resources.db.params.username = "alan"
   resources.db.params.password = "secretpw"
   resources.db.params.dbname = "*LOCAL"

Alan Seiden Consulting                44          From Zero to ZF on IBM i: Your first Zend Framework project
Other useful keys for application.ini
   ; os="i5" ensures adapter will know we're an IBM i(i5)
   resources.db.params.os = "i5"

   ; persistent=true speeds performance
   resources.db.params.persistent = true

   ; autocommit=DB2_AUTOCOMMIT_ON for insert/update/delete
   resources.db.params.driver_options.autocommit = DB2_AUTOCOMMIT_ON


   ; i5_naming=DB2_I5_NAMING_ON means '/', not '.', is library sep.
   ;                            and allows library lists
   resources.db.params.driver_options.i5_naming = DB2_I5_NAMING_ON

   ; i5_libl= easy way to specify a library list (see i5_naming above)
   resources.db.params.driver_options.i5_libl = "LIB1 LIB2"



Alan Seiden Consulting            45          From Zero to ZF on IBM i: Your first Zend Framework project
Still more optional keys for application.ini
   ; isDefaultTableAdapter means to use this adapter for tables
   resources.db.isDefaultTableAdapter = true


   ;profiler is optional. lets you measure query performance.
   resources.db.params.profiler.class = "Zend_Db_Profiler_Firebug"
   resources.db.params.profiler.enabled = true




   Are we done? No… see the next slide for one more
    critical step




Alan Seiden Consulting            46          From Zero to ZF on IBM i: Your first Zend Framework project
Install IBM i-optimized DB2 adapter

   • As of ZF 1.x, the Db2.php adapter doesn't work quite
      right for all IBM i's use cases, such as:
          DB2_I5_NAMING = On
                 • Because library/schema separator is hardcoded as '.'
          Zend_Db_Table performance (metadata retrieval is slow)
          Ability to utilize certain .INI settings


   • I have a temporary fix for you. For ZF 2.x I’ll be working
      with the ZF team on an official fix.

   • See next slide for instructions


Alan Seiden Consulting                        47            From Zero to ZF on IBM i: Your first Zend Framework project
Installing my DB2 adapter fix
   •       Download corrected adapter from
           http://www.alanseiden.com/code/ibm-i-db2-zf-adapter.zip
   •       Extract instructions.txt and Db2.php
   •       Place Db2.php in the folder “library/Strategic/Db/Adapter/”
   •       Note: the “Adapter namespace” (first part of class name) is
           “Strategic” instead of “Zend.” This can be any name you choose.




Alan Seiden Consulting                     48           From Zero to ZF on IBM i: Your first Zend Framework project
Update application.ini with adapter name

   • In application.ini, add this setting:
           resources.db.params.adapterNamespace =
           Strategic_Db_Adapter

   • Now you are good to go
               In particular, library lists will work




Alan Seiden Consulting                      49           From Zero to ZF on IBM i: Your first Zend Framework project
Access a
DB2 table
Zend_Db_Table is one way to access data

   • Table classes created for us by Zend_Tool
   • You provide 2 names: 1) class to create 2) table name
               Example: I have a table called CUSTFILE
               Type “zf create dbtable Custfile CUSTFILE” (if uppercase table)
               See resulting class file in screen shot below
   • Then edit the class, esp. when primary key is not ‘id’




Alan Seiden Consulting                    51           From Zero to ZF on IBM i: Your first Zend Framework project
Read records using table class

   In controllers/Customer_Controller.php:
       public function listAction()
       {
               $custfile = new Application_Model_DbTable_Custfile();
               $custs = $custfile->fetchAll();
               $this->view->customers = $custs;
       }

   In views/scripts/customer/list.phtml (omitting the class and style tags):
   <H1>Customer list from CUSTFILE table</H1>
   <table class="list">
   <tr style="font-weight: bold; text-align: left;"><th>Number</th><th>Name</
     th><th>Status</th></tr>
   <?php
   $customers = $this->customers;
   foreach ($customers as $customer) {
   echo "<tr><td>{$customer->CUSTNO}</td>
            <td>{$customer->LNAME}</td>
            <td>{$customer->STATUS}</td></tr>";
   }
   ?>
Alan Seiden Consulting
   </table>                                       52            From Zero to ZF on IBM i: Your first Zend Framework project
Display results

   • URL: /customer/list




Alan Seiden Consulting     53   From Zero to ZF on IBM i: Your first Zend Framework project
We did it!

   • Now you know how to create a Zend Framework
         project on IBM i that will work on the first try, DB2
         and all
            ZF version 1.x. For 2.x, see my webcast on Dec. 11, 2012

   • These slides are online where you can refer to
         them

   • Send me feedback so I can continue to improve the
         process




Alan Seiden Consulting                 54          From Zero to ZF on IBM i: Your first Zend Framework project
Resources for learning ZF

      • Tutorials
               Official ZF quickstart: http://framework.zend.com/manual/en/
                learning.quickstart.html

               Rob Allen’s (author of Zend Framework in Action): http://
                akrabat.com/zend-framework-tutorial/

      • Online training
               (Zend) http://shop.zend.com/en/php-training/zend-framework-
                fundamentals.html

      • Forums
               http://forums.zend.com

      • User groups (Bring your laptop and ask a question!)
               http://framework.zend.com/community/groups




Alan Seiden Consulting                       55            From Zero to ZF on IBM i: Your first Zend Framework project
Questions
Alan’s upcoming appearances

  http://alanseiden.com/presentations/upcoming

   Oct. 17               Webcast   iPro Developer Online Conference
   Oct. 22-25            ZendCon   Santa Clara, Calif.
   Dec. 11               Webcast    Zend Framework 2 and IBM i




Alan Seiden Consulting                57        From Zero to ZF on IBM i: Your first Zend Framework project
Contact | Get tips

   Alan Seiden
   Alan Seiden Consulting
   Ho-Ho-Kus, NJ


   alanseiden.com




   Free tips newsletter: alanseiden.com/tips



   alan@alanseiden.com      ●   201-447-2437 ●     twitter: @alanseiden

Alan Seiden Consulting              58         From Zero to ZF on IBM i: Your first Zend Framework project

More Related Content

PDF
IBM i: Fertile Ground for PHP Developers
PDF
Create a welcoming development environment on IBM i
PDF
Web services on IBM i with PHP and Zend Framework
PDF
Strategic Modernization with PHP on IBM i
PDF
PHP Batch Jobs on IBM i
PDF
DB2 and PHP in Depth on IBM i
PDF
Browser tools that make web development easier
PDF
PHP Toolkit from Zend and IBM: Open Source on IBM i
IBM i: Fertile Ground for PHP Developers
Create a welcoming development environment on IBM i
Web services on IBM i with PHP and Zend Framework
Strategic Modernization with PHP on IBM i
PHP Batch Jobs on IBM i
DB2 and PHP in Depth on IBM i
Browser tools that make web development easier
PHP Toolkit from Zend and IBM: Open Source on IBM i

What's hot (20)

PDF
Web Performance First Aid
PPTX
Getting started with PHP on IBM i
PDF
Performance tuning with zend framework
PPTX
Fundamentals of performance tuning PHP on IBM i
PPTX
Install MariaDB on IBM i - Tips, troubleshooting, and more
PPTX
PHP Installed on IBM i - the Nickel Tour
PPTX
Zend Products and PHP for IBMi
PPTX
PHP on IBM i Tutorial
PDF
Running open source PHP applications on you IBM i
PPT
PHP on Windows - What's New
KEY
Zend_Tool: Practical use and Extending
PDF
Zend Core on IBM i - Security Considerations
PPTX
PHP and Platform Independance in the Cloud
PDF
Performance tuning PHP on IBMi
PDF
IBM Connections administration – keep your systems running the right way
PPTX
Zend con 2016 bdd with behat for beginners
PDF
Zend con what-i-learned-about-mobile-first
PDF
IBM Connect 2016 - 60+ in 60 - Admin Tips Power Hour
PPTX
IBM Connections Adminblast - Connect17 (DEV 1268)
PPTX
What is cool with Domino V10, Proton and Node.JS, and why would I use it in ...
Web Performance First Aid
Getting started with PHP on IBM i
Performance tuning with zend framework
Fundamentals of performance tuning PHP on IBM i
Install MariaDB on IBM i - Tips, troubleshooting, and more
PHP Installed on IBM i - the Nickel Tour
Zend Products and PHP for IBMi
PHP on IBM i Tutorial
Running open source PHP applications on you IBM i
PHP on Windows - What's New
Zend_Tool: Practical use and Extending
Zend Core on IBM i - Security Considerations
PHP and Platform Independance in the Cloud
Performance tuning PHP on IBMi
IBM Connections administration – keep your systems running the right way
Zend con 2016 bdd with behat for beginners
Zend con what-i-learned-about-mobile-first
IBM Connect 2016 - 60+ in 60 - Admin Tips Power Hour
IBM Connections Adminblast - Connect17 (DEV 1268)
What is cool with Domino V10, Proton and Node.JS, and why would I use it in ...
Ad

Viewers also liked (6)

PPTX
Nuclear transformation (physics)
PDF
iSecurity Data Sheet March 2016
PPTX
Developing Secure IBM i Applications
PPT
Lecture 25.2- Nuclear Transformations
PDF
Working with the IFS on System i
PPTX
Structure of atom
Nuclear transformation (physics)
iSecurity Data Sheet March 2016
Developing Secure IBM i Applications
Lecture 25.2- Nuclear Transformations
Working with the IFS on System i
Structure of atom
Ad

Similar to From Zero to ZF: Your first zend framework project on ibm i (20)

PDF
Getting started with PHP on IBM i
PDF
What's new with Zend server
PPT
Edp bootstrapping a-software_company
PDF
Zend Framework Handout
PDF
Zend Framework Handout
PPTX
MVC Frameworks for building PHP Web Applications
PPTX
Zend Framwork presentation
PPTX
Web application development using zend framework
PDF
Building Web Applications with Zend Framework
PPTX
Getting up & running with zend framework
PPTX
Getting up and running with Zend Framework
PDF
Zend Framework 1.8 workshop
PDF
DPC2007 Zend Framework (Gaylord Aulke)
 
PPT
PPT
Greenathan
PPT
Greenathan
PPT
PPT
PPT
werwer
PPT
Getting started with PHP on IBM i
What's new with Zend server
Edp bootstrapping a-software_company
Zend Framework Handout
Zend Framework Handout
MVC Frameworks for building PHP Web Applications
Zend Framwork presentation
Web application development using zend framework
Building Web Applications with Zend Framework
Getting up & running with zend framework
Getting up and running with Zend Framework
Zend Framework 1.8 workshop
DPC2007 Zend Framework (Gaylord Aulke)
 
Greenathan
Greenathan
werwer

Recently uploaded (20)

PPTX
Programs and apps: productivity, graphics, security and other tools
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Approach and Philosophy of On baking technology
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
cuic standard and advanced reporting.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
Big Data Technologies - Introduction.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Encapsulation theory and applications.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Programs and apps: productivity, graphics, security and other tools
“AI and Expert System Decision Support & Business Intelligence Systems”
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Review of recent advances in non-invasive hemoglobin estimation
MIND Revenue Release Quarter 2 2025 Press Release
Understanding_Digital_Forensics_Presentation.pptx
Unlocking AI with Model Context Protocol (MCP)
Approach and Philosophy of On baking technology
Chapter 3 Spatial Domain Image Processing.pdf
cuic standard and advanced reporting.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
sap open course for s4hana steps from ECC to s4
Big Data Technologies - Introduction.pptx
20250228 LYD VKU AI Blended-Learning.pptx
Encapsulation theory and applications.pdf
Spectral efficient network and resource selection model in 5G networks
MYSQL Presentation for SQL database connectivity
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy

From Zero to ZF: Your first zend framework project on ibm i

  • 1. “From Zero to ZF” on IBM i Your first Zend Framework project Alan Seiden Consulting alanseiden.com
  • 2. My focus Advancing PHP on IBM i • PHP project leader, Zend/IBM Toolkit • Contributor, Zend Framework DB2/i enhancements • Developer, Best Web Solution, IBM/Common • Authority, subsecond web performance on IBM i/iSeries Alan Seiden Consulting 2 From Zero to ZF on IBM i: Your first Zend Framework project
  • 3. Contact information Alan Seiden alan@alanseiden.com 201-447-2437 alanseiden.com twitter: @alanseiden Alan Seiden Consulting 3 From Zero to ZF on IBM i: Your first Zend Framework project
  • 4. Where to download these slides From my site http://alanseiden.com/presentations On SlideShare http://slideshare.net/aseiden The latest version will be available on both sites Alan Seiden Consulting 4 From Zero to ZF on IBM i: Your first Zend Framework project
  • 5. Whom this talk is for • Experienced PHP developers…  …will see a step-by-step demonstration of how to create a Zend Framework project that runs on the first try • Zend Framework developers…  …will learn a streamlined, methodical approach that uses today’s tools • Others…  …will maybe see something interesting. To beginning PHP developers: Regular PHP is fine. You will know when the time is right to jump in with ZF. Alan Seiden Consulting 5 From Zero to ZF on IBM i: Your first Zend Framework project
  • 6. What we’ll do today • Help you get a feeling of SUCCESS with Zend Framework (v1.x) on IBM i • We’ll get you past common sticking points:  Installing ZF  Creating a remote project (IFS-based) in Zend Studio  Apache web server configuration, including “rewrite” rules  Adding to the default project  Getting library lists to work (and other db2 on i options, too) • I’ll provide additional resources for study • And answer your questions Alan Seiden Consulting 6 From Zero to ZF on IBM i: Your first Zend Framework project
  • 8. What ZF is • PHP-based framework with best practices for PHP5, OO • Free and open source • Cross-platform • Developed by the community and full-time, dedicated Zend employees, with help from other important technology companies • Downloaded millions of times Alan Seiden Consulting 8 From Zero to ZF on IBM i: Your first Zend Framework project
  • 9. A component library AND a full framework • ZF includes popular individual components for mail, security, forms, PDF, web services, and much more.  These components can be used from “regular” PHP  They are the “gateway drug” of ZF • As a full stack framework, ZF includes a Model-View- Controller (MVC) architecture that makes apps easy to maintain Alan Seiden Consulting 9 From Zero to ZF on IBM i: Your first Zend Framework project
  • 10. Friendly URLs • ZF supports friendly URLs by default • URLs route to PHP script and function/method  Defined by ZF’s router  URL split into script/method/variables according to naming convention (controller and action) • Example: http://mysite.com/customer/list/division/2 • In example above:  Script: CustomerController.php  Method/function: listAction()  division = 2 Alan Seiden Consulting 10 From Zero to ZF on IBM i: Your first Zend Framework project
  • 11. MVC directory structure: more than MVC • Model, View, Controller folders, of course • “Public” folder, which is the only public folder  Consistent with best security practices  Public script index.php initiates a “Front controller” • Other resources such as configuration files, layouts, code libraries and documentation Alan Seiden Consulting 11 From Zero to ZF on IBM i: Your first Zend Framework project
  • 12. How ZF fits with Zend’s product line • Zend Server http://www.zend.com/en/products/server/  A value-added PHP install for IBM i, Linux, Windows, Mac OS X  As “free” Community Edition (CE) and regular edition  Installs a copy of Zend Framework • Zend Studio http://www.zend.com/en/products/studio/  Integrated Development Environment (IDE)  IBM i edition is “free” thanks to IBM/Zend relationship  Also installs its own copy of Zend Framework! (on your PC) • Zend Framework http://framework.zend.com  Can work with any PHP 5.x install, anywhere, but of course it works very well with the above products Alan Seiden Consulting 12 From Zero to ZF on IBM i: Your first Zend Framework project
  • 14. It’s already there--or download fresh • Installed automatically with Zend Server /usr/local/zendsvr/share/ZendFramework/library/zend • Updates available at http://framework.zend.com/download/ latest  Unzip into /usr/local… (see above) or your ZF library folder • PEAR channel on Google Code  Instructions: http://engineeredweb.com/blog/10/6/ installing-and-using-zend-framework-pear • More ideas: http://mikepavlak.blogspot.com/2010/09/ updating-zend-framework-on-ibm-i.html Alan Seiden Consulting 14 From Zero to ZF on IBM i: Your first Zend Framework project
  • 15. Zend Server’s easy default install • This way is fine when you are starting out • Folder is /usr/local/zendsvr/share/ZendFramework/  Contains library/zend • PHP.INI specifies “/usr/local/zendsvr/share/ ZendFramework/” in its include_path variable  All your PHP applications will be able to find the library/ zend folder without any further work Alan Seiden Consulting 15 From Zero to ZF on IBM i: Your first Zend Framework project
  • 16. Step-by-step ZF project
  • 17. Step by step ZF configuration • Set up SSH  (server) on IBM i  (client) in Zend Studio • Create project directory on remote server (IBM i) • Use Zend_Tool to generate skeleton project  We’ll use Zend Studio’s Zend_Tool integration rather than PASE’s zf.sh script, though both work • Configure Apache webserver virtual host • Test basic project. It should run at this point • Configure DB2 adapter for IBM i and test db table • Create additional controller/action Alan Seiden Consulting 17 From Zero to ZF on IBM i: Your first Zend Framework project
  • 19. SSH = Secure Shell protocol • Faster and more secure than FTP • Zend Studio connects over SSH to the IBM i  SSH server (daemon) is IBM i  SSH client is Zend Studio • Let’s see how to set up the server and client Alan Seiden Consulting 19 From Zero to ZF on IBM i: Your first Zend Framework project
  • 20. Starting SSH daemon (sshd) on IBM i • i6.1 or higher: one step creates keys and starts server STRTCPSVR *SSHD • V5R4: two steps First, create public/private key pairs: CALL QP2TERM ssh-keygen -t rsa1 -f /QOpenSys/QIBM/UserData/SC1/OpenSSH/ openssh-3.5p1/etc/ssh_host_key -N "" ssh-keygen -t dsa -f /QOpenSys/QIBM/UserData/SC1/OpenSSH/ openssh-3.5p1/etc/ssh_host_dsa_key -N "" ssh-keygen -t rsa -f /QOpenSys/QIBM/UserData/SC1/OpenSSH/ openssh-3.5p1/etc/ssh_host_rsa_key -N " For more on sshd setup, see “Young i Professionals” wiki: Then start sshd (“&” means to run in background): /usr/sbin/sshd & http://174.79.32.155/wiki/ index.php/PASE/SSHSetup Alan Seiden Consulting 20 From Zero to ZF on IBM i: Your first Zend Framework project
  • 21. Zend Studio as an SSH client • Open the Remote Systems perspective  (Window / Perspective / Remote Systems) • Click the “Define a connection…” button Alan Seiden Consulting 21 From Zero to ZF on IBM i: Your first Zend Framework project
  • 22. Define connection to IBM i 1. Choose SSH as connection type. Click “Next.” 2. Provide host name (IP or domain name) of your “i”. Click “Finish.” Alan Seiden Consulting 22 From Zero to ZF on IBM i: Your first Zend Framework project
  • 23. Done! We’re connected to IBM i 1. On left: Remote System Explorer, an IFS file list 2. On right: Remote Shell, handy for entering shell commands (List of shell commands: http://ss64.com/bash) Alan Seiden Consulting 23 From Zero to ZF on IBM i: Your first Zend Framework project
  • 24. Create project directory
  • 25. Create IFS directory for project • Typical directory pattern: /www/anything/htdocs • Example: /www/zfdemo/htdocs • From 5250 screen, use “md” command for each dir level • Or, better, use “mkdir” from PASE or Remote Shell in Zend Studio For example: “mkdir –p /www/zfdemo/htdocs” • “-p” means “create parent folders if necessary” • Verify it was created: WRKLNK or “ls /www/zfdemo/htdocs” Alan Seiden Consulting 25 From Zero to ZF on IBM i: Your first Zend Framework project
  • 26. Create project with Zend_Tool
  • 27. Zend_Tool creates ZF files/folders for us • It’s a component that sets up our project correctly and quickly • Command-line interface: “zf” (lower case) • UNIX or PASE: a shell script called zf.sh • Zend Studio: use the “Zend Tool” menu option from the Project menu • Keyboard shortcut: CTRL+2 • Another Studio interface to Zend_Tool is the “New…” wizard from the File menu • Underneath, it calls the “zf” commands, so you might want to try it to learn the “zf” commands better • Here we will use the “Zend Tool”option from Project menu • Make sure you clicked on the “PHP Explorer” pane first • zf command line looks like: Alan Seiden Consulting 27 From Zero to ZF on IBM i: Your first Zend Framework project
  • 28. Launch Zend Tool command entry • Click on the PHP Explorer pane • Click Project, then Zend Tool  Shortcut: CTRL+2 Alan Seiden Consulting 28 From Zero to ZF on IBM i: Your first Zend Framework project
  • 29. Create the project • Let’s name the project “zfdemo”  Will fit nicely with the folder we created, /www/zfdemo/htdocs • Type these commands into Zend Tool window:  Go to Studio’s workspace root: “cd /”  Create the project: “zf create project zfdemo” • Press F5 or File/Refresh to refresh view of files Alan Seiden Consulting 29 From Zero to ZF on IBM i: Your first Zend Framework project
  • 30. Our project is there • You should see a complete project structure called zfdemo IndexController: default controller indexAction: default action within a controller “index” is a default name (Compare index.html as the usual homepage of a website) • The project exists in Studio’s workspace • Now we should link it to IFS for automatic synchronization Alan Seiden Consulting 30 From Zero to ZF on IBM i: Your first Zend Framework project
  • 31. Enable remote synch of project with IFS • Right-click the project • Choose “properties,” then “Remote Server Support” Alan Seiden Consulting 31 From Zero to ZF on IBM i: Your first Zend Framework project
  • 32. Set up the Remote Support settings • Click “Enable remote connection properties” • Choose the remote connection you created earlier • Type the Project Directory you created earlier  Example: /www/zfdemo/htdocs • Leave “On Save” as upload method; click OK Alan Seiden Consulting 32 From Zero to ZF on IBM i: Your first Zend Framework project
  • 33. Upload the project to IFS • You’ll be asked: “Do you want to upload all files to the remote server?”  Click “Yes” then “Finish” • Project is now on IFS Alan Seiden Consulting 33 From Zero to ZF on IBM i: Your first Zend Framework project
  • 34. Project files are now on IFS • Verify with Remote Systems Explorer (use F5) • or WRKLNK ‘/www/zfdemo’ Alan Seiden Consulting 34 From Zero to ZF on IBM i: Your first Zend Framework project
  • 36. Control access/routing to our project • The folder called “public”is Document Root, containing index.php • Use Apache “rewrite rules” to route all ZF requests to index.php • ZF’s router will examine the original REQUEST_URI to route request to correct controller and action Alan Seiden Consulting 36 From Zero to ZF on IBM i: Your first Zend Framework project
  • 37. More about Apache config • For performance and security, do not use .htaccess files in production systems • Put configurations in main httpd.conf instead • See example of correct virtual host config on next slide… Alan Seiden Consulting 37 From Zero to ZF on IBM i: Your first Zend Framework project
  • 38. Section from /www/zendsvr/conf/ httpd.conf # use your choice of IP and port, if they are not already in use elsewhere # Use 80 for a public site and 443 for SSL-encrypted Listen *:12345 # NameVirtualHost allows us to share an IP address/port among multiple sites NameVirtualHost *:12345 <VirtualHost *:12345> DocumentRoot "/www/zfdemo/htdocs/public" # specify ServerName if using NameVirtualHost (must match URL typed in browser) ServerName 1.2.3.4:12345 # This should be omitted in the production environment SetEnv APPLICATION_ENV development #Detailed documentation: http://framework.zend.com/manual/en/project-structure.rewrite.html RewriteEngine off <Location /> RewriteEngine On RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [NC,L] RewriteRule ^.*$ /index.php [NC,L] </Location> <Directory "/www/zfdemo/htdocs/public"> Options Indexes MultiViews FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory> </VirtualHost> Alan Seiden Consulting 38 From Zero to ZF on IBM i: Your first Zend Framework project
  • 39. Update Apache conf and then restart • Update /www/zendsvr/conf/httpd.conf with a config for your ZF project • Previous slide contains a solid template for you • Restart Apache STRTCPSVR SERVER(*HTTP) RESTART(*HTTP) HTTPSVR(ZENDSVR) • The sample project should run! • http://yourserver:port Alan Seiden Consulting 39 From Zero to ZF on IBM i: Your first Zend Framework project
  • 41. Zend_Tool continues to help • Let’s create a Customer controller • And then an action to show a list of customers  Call it “list” • Once again, launch Studio’s Zend_Tool window • Create the Customer controller: cd /zfdemo zf create controller Customer • Press F5 to refresh, then create the ‘list’ action: zf create action list Customer • Refresh again (F5) Alan Seiden Consulting 41 From Zero to ZF on IBM i: Your first Zend Framework project
  • 42. Our new controller and action are there If you open the CustomerController.php file you will find: public function listAction() { } Alan Seiden Consulting 42 From Zero to ZF on IBM i: Your first Zend Framework project
  • 44. Configure Zend_Db adapter for Db2 At a minimum, create these settings: • adapter type (Db2) • username (may be blank) • password (may be blank) • dbname (may be blank or an entry from WRKRDBDIRE) Run: zf configure db-adapter "adapter=Db2&username=alan&password=secretpw&dbname=*LOCAL" The above zf command creates four keys in application.ini: resources.db.adapter = Db2 resources.db.params.username = "alan" resources.db.params.password = "secretpw" resources.db.params.dbname = "*LOCAL" Alan Seiden Consulting 44 From Zero to ZF on IBM i: Your first Zend Framework project
  • 45. Other useful keys for application.ini ; os="i5" ensures adapter will know we're an IBM i(i5) resources.db.params.os = "i5" ; persistent=true speeds performance resources.db.params.persistent = true ; autocommit=DB2_AUTOCOMMIT_ON for insert/update/delete resources.db.params.driver_options.autocommit = DB2_AUTOCOMMIT_ON ; i5_naming=DB2_I5_NAMING_ON means '/', not '.', is library sep. ; and allows library lists resources.db.params.driver_options.i5_naming = DB2_I5_NAMING_ON ; i5_libl= easy way to specify a library list (see i5_naming above) resources.db.params.driver_options.i5_libl = "LIB1 LIB2" Alan Seiden Consulting 45 From Zero to ZF on IBM i: Your first Zend Framework project
  • 46. Still more optional keys for application.ini ; isDefaultTableAdapter means to use this adapter for tables resources.db.isDefaultTableAdapter = true ;profiler is optional. lets you measure query performance. resources.db.params.profiler.class = "Zend_Db_Profiler_Firebug" resources.db.params.profiler.enabled = true Are we done? No… see the next slide for one more critical step Alan Seiden Consulting 46 From Zero to ZF on IBM i: Your first Zend Framework project
  • 47. Install IBM i-optimized DB2 adapter • As of ZF 1.x, the Db2.php adapter doesn't work quite right for all IBM i's use cases, such as:  DB2_I5_NAMING = On • Because library/schema separator is hardcoded as '.'  Zend_Db_Table performance (metadata retrieval is slow)  Ability to utilize certain .INI settings • I have a temporary fix for you. For ZF 2.x I’ll be working with the ZF team on an official fix. • See next slide for instructions Alan Seiden Consulting 47 From Zero to ZF on IBM i: Your first Zend Framework project
  • 48. Installing my DB2 adapter fix • Download corrected adapter from http://www.alanseiden.com/code/ibm-i-db2-zf-adapter.zip • Extract instructions.txt and Db2.php • Place Db2.php in the folder “library/Strategic/Db/Adapter/” • Note: the “Adapter namespace” (first part of class name) is “Strategic” instead of “Zend.” This can be any name you choose. Alan Seiden Consulting 48 From Zero to ZF on IBM i: Your first Zend Framework project
  • 49. Update application.ini with adapter name • In application.ini, add this setting: resources.db.params.adapterNamespace = Strategic_Db_Adapter • Now you are good to go  In particular, library lists will work Alan Seiden Consulting 49 From Zero to ZF on IBM i: Your first Zend Framework project
  • 51. Zend_Db_Table is one way to access data • Table classes created for us by Zend_Tool • You provide 2 names: 1) class to create 2) table name  Example: I have a table called CUSTFILE  Type “zf create dbtable Custfile CUSTFILE” (if uppercase table)  See resulting class file in screen shot below • Then edit the class, esp. when primary key is not ‘id’ Alan Seiden Consulting 51 From Zero to ZF on IBM i: Your first Zend Framework project
  • 52. Read records using table class In controllers/Customer_Controller.php: public function listAction() { $custfile = new Application_Model_DbTable_Custfile(); $custs = $custfile->fetchAll(); $this->view->customers = $custs; } In views/scripts/customer/list.phtml (omitting the class and style tags): <H1>Customer list from CUSTFILE table</H1> <table class="list"> <tr style="font-weight: bold; text-align: left;"><th>Number</th><th>Name</ th><th>Status</th></tr> <?php $customers = $this->customers; foreach ($customers as $customer) { echo "<tr><td>{$customer->CUSTNO}</td> <td>{$customer->LNAME}</td> <td>{$customer->STATUS}</td></tr>"; } ?> Alan Seiden Consulting </table> 52 From Zero to ZF on IBM i: Your first Zend Framework project
  • 53. Display results • URL: /customer/list Alan Seiden Consulting 53 From Zero to ZF on IBM i: Your first Zend Framework project
  • 54. We did it! • Now you know how to create a Zend Framework project on IBM i that will work on the first try, DB2 and all  ZF version 1.x. For 2.x, see my webcast on Dec. 11, 2012 • These slides are online where you can refer to them • Send me feedback so I can continue to improve the process Alan Seiden Consulting 54 From Zero to ZF on IBM i: Your first Zend Framework project
  • 55. Resources for learning ZF • Tutorials  Official ZF quickstart: http://framework.zend.com/manual/en/ learning.quickstart.html  Rob Allen’s (author of Zend Framework in Action): http:// akrabat.com/zend-framework-tutorial/ • Online training  (Zend) http://shop.zend.com/en/php-training/zend-framework- fundamentals.html • Forums  http://forums.zend.com • User groups (Bring your laptop and ask a question!)  http://framework.zend.com/community/groups Alan Seiden Consulting 55 From Zero to ZF on IBM i: Your first Zend Framework project
  • 57. Alan’s upcoming appearances http://alanseiden.com/presentations/upcoming Oct. 17 Webcast iPro Developer Online Conference Oct. 22-25 ZendCon Santa Clara, Calif. Dec. 11 Webcast Zend Framework 2 and IBM i Alan Seiden Consulting 57 From Zero to ZF on IBM i: Your first Zend Framework project
  • 58. Contact | Get tips Alan Seiden Alan Seiden Consulting Ho-Ho-Kus, NJ alanseiden.com Free tips newsletter: alanseiden.com/tips alan@alanseiden.com ● 201-447-2437 ● twitter: @alanseiden Alan Seiden Consulting 58 From Zero to ZF on IBM i: Your first Zend Framework project