SlideShare a Scribd company logo
1 of 6
Download to read offline
PHP & Zend Framework Tutorial
I did a lot of googling, installing, re-installing, … but finally got my first php project to
work. I used WAMP for the apache install, the Zend Framework as an MVC, and
PostGreSQL as a backend database. Below you can find a basic tutorial on how to get
started. Included are following steps:

   1.   Install & configure WAMP
   2.   Configure PHP
   3.   Install & configure PostGres
   4.   Set up the Zend Framework
   5.   Start programming

I’m gonna try to keep everything as simple as possible. Downside is that you’ll have to
try & configure some things on your own. On the other hand it’ll keep this tutorial from
becoming too big (and you probably didn’t even got to reading this sentence)… Oh yeah,
I’m doing this on my Windows XP system, I don’t know how differently all of this
should be done on other systems.

1. Install & configure WAMP.
Why WAMP? Well it’s the Windows version of the popular LAMP distribution and the
installer configures a lot of things for you. I started with installing & configuring
everything (Apache, MySQL/PostGres & PHP) separately which worked (after some
time), but I want to spare you the frustrations I had to endure.

I’m not gonna tell you how to download it and click next during the installer. The most
important thing is the ‘httpd.conf’-file which configures the server. Following parameters
are quite important (but should be set correctly after installing WAMP):
    - the parameter “documentRoot” points to your ‘www’-folder, where you can drop
        your PHP-files that can be viewed by browser when the server’s URL is given
    - the parameter “loadModule” points to the PHP configuration that should be used
        (PHP runtime environment normally is a separate install – Apache can’t handle
        PHP on his own)

Important! I installed WAMP in my “program files” folder, so I recommend you do this
too, otherwise you will have to adjust the php.ini file, which is discussed later.

So, normally no configuration is need, and after installing you should see an “It works!”
when you browse to your http://localhost. If you are having problems, make sure all
service are running.

2. Configure PHP
The WAMP install will do a lot for you, but you will still have to set your system
variables:

   -   Path: add your php folder (e.g: …existingPathValues…;C:Program
       Fileswampphp)
   - PHPRC (=PHP Runtime Conf): e.g. “C:Program Fileswampphp”
You can google if you don’t know how to set system variables, but remember to restart
your PC after having done this.

A very important file is php.ini! It configures your PHP runtime environment. I’ll list the
most important parameters (to me):
(remember to remove the “;” in front of a parameter to uncomment it)
    - display_errors: set it to “On”
    - display_startup_errors: set it to “On”
    - log_errors: set it to “On”
       (this is good for a dev environment but remember it affects performance)
    - extension=… (to add dll’s – we’ll need some to connect to PostGres, so I’ll come
       back to it later)
    - extension_dir: to tell PHP where it can find dll’s that are added through the
       ‘extension’ parameters
    - include_path: used to include external (php-)classes that can be used in your
       project (we’ll include the Zend framework classes, so I’ll come back to this later)

Also something nice is PDO, when learning PHP you’ll stumble on to this – give it some
extra attention!

3. Install & configure PostGres
Why PostGres? Well, because we’re going to need it for a client. We’ll have an expert
setting it up, but it always to know a little bit about what (or who) you are ‘doing’.
Normally I would have gone for MySQL (which is part of and configured by WAMP).

I suggest you follow the installer. Then open PgAdminIII (part of the installer) and
double-click on your server. Enter your password (the one you entered during install) ,
right-click on ‘databases’ and select “New database…”. For this tutorial enter
“firstphpdb” for the name and click “OK”.

Then goto ‘Tools’ in the menu and select ‘Query tool’. Enter the following query:

   CREATE TABLE users (
      id serial PRIMARY KEY,
      firstname varchar(50) UNIQUE NOT NULL,
      lastname varchar(50) UNIQUE NOT NULL,
      dateCreated timestamp DEFAULT current_timestamp
   );
Then click the ‘Run’ button. This will create the “Users” table for you (under Schema’s
  Public Tables). I guess you can find out on your how to enter some names in there.

This cheat sheet is quite useful.

4. Set up the Zend Framework
OK, why Zend? Well it’s quite popular and IBM also likes it. Since I’m a big fan of
Lotus Notes I’ll follow IBM on this. I’ll leave the discussion on which framework to use
to the real PHP freaks.

First, we need to make sure we can use the Zend classes. We do this in our php.ini
through the ‘include_path’ parameter:

   ; Windows: "path1;path2"
   include_path = ".;C:Program FilesZendZendFramework-1.0.1library"

Of course this setting depend on where you extracted your Zend Framework. Don’t
forget to download it.

Secondly, you’ll need to understand how it works and should be used. I’ll just explain the
MVC setup, but Zend can do much more (I haven’t tried the other features, I’ll
probably some more when I do). I’ll try to explain the MVC on a step-by-step basis:

   1. Remove everything from you document root (the www-folder of your WAMP
      installation). First we’re going to create an .htaccess file in this folder. This file…
      Tip: You can’t create a file that starts with a dot in Explorer, use the “Save as…”
      function in Notepad.
   2. Now, we’ll create an index.php file and drop it in our root folder (the www-folder
      of your WAMP installation). This file will launch when users browse to your
      server. You can find the file here. Everything is explained in the file itself:

   <?php
   try {
         // full error reporting (you can actually omit this because we also set this in php.ini)
         error_reporting(E_ALL);

        //includes: (remember the include_path in your php.ini? it’s used here)
        include_once('Zend/Loader.php');

        //load the classes
        //the following translates into 'include(Zend/Controller/Front.php)'
        Zend_Loader::loadClass('Zend_Controller_Front');
        Zend_Loader::loadClass('Zend_Db');
        Zend_Loader::loadClass('Zend_Db_Table');

        //configure the database
        $options = array(
                 'host' => 'localhost' ,
'username' => 'postgres' ,
              'password' => 'lotusnotes' ,
              'dbname' => 'firstphpdb'
     );
     $db = Zend_Db::factory( 'PDO_PGSQL' , $options );
     //Using Zend_Db_Table is not mandatory,
     //But it will help write models because it assists in 'fast-writing' sql-queries
     //If we omit Zend_Db_Table we should use the PDO model
     Zend_Db_Table::setDefaultAdapter( $db );

     //configure the front controller (everything start here!)
     $controller = Zend_Controller_Front::getInstance();
     $controller->setControllerDirectory( './FirstPHPProject/controllers');

     //disable automatic view rendering (important, but look at Zend docs for the explanation)
     $controller->setParam('noViewRenderer' , true);

     //run the controller
     $controller->dispatch();
} catch (Exception $e) {
              echo $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine() . "n";
}

3. Now, because of the Zend_Controller in the index.php file, we need to create a
   directory structure for our project that the Zend_Controller can use. It is very
   important that you create it exactly like the Zend framework wants it:
                                           The Zend_Controller will translate the
                                           url’s that are used. E.g. if you enter
                                           “localhost/index/index, Zend_Controller
                                           will look for the ‘indexAction’ in the
                                           ‘IndexController’ class in the controllers
                                           directory. If you enter
                                           “localhost/users/view”, it will look for the
                                           ‘viewAction’ in the ‘UsersController’.

                                                  Now, you can ignore the “.cache” and
                                                  “.settings” folder. Because I’m using
                                                  Eclipse PDT as an editor, Eclipse created
                                                  these folders.
                                                  You can’t see the files, but .htaccess and
                                                  index.php are at the same level as the folder
                                                  “FirstPHPProject” and “public”.

     Now it’s up to you to create the same folder structure.

4. I hope you already know the basics of an MVC framework, because I’m not going
   to explain it. I’m just going to list the files you should create in each folder and
   explain some thing in the files themselves in the next chapter…
7. Start programming
Is started of using the Zend Editor, which is very nice, but Sven Dens recommended
using the Eclipse PDT plugin which has recently got it’s first 1-release. Since I’ve
already used Eclipse and this is becoming our company ‘standard’ I went with it. So for
no problems…

You can find my entire www-folder in the post, so I suggest you download it. This is how
it should look like (left is in Eclipse, right in Zend Editor):




Most explanations are found in the files themselves. I’ll discuss the basics here.
The Controllers

As mentioned before, the Zend_Controller handles the requests and translates them into
‘actions’ from ‘controller’ classes in the “Controllers” folder.

Let’s take the ‘contactAction’ ‘IndexController’ as an example which we can call through
http://localhost/index/contact.

The ‘init()’ function as called every time an instance of the IndexController is created. In
here, we initialize the view (which we will render at the end of the the ‘contactAction’).
We don’t need to specify which view to use: Zend will look for a file called
contact.phtml (=action name + .phtml) the in the “index” directory (=controller name) in
the “scripts” folder. So make sure it exists. Note that everything is case sensitive!

Note: if you omit something, Zend will default to ‘index’. E.g. if you enter
http://localhost is will translate to http://localhost/index/index. If you enter
http://localhost/users is will translate to http://localhost/users/index.

The Views

As mentioned in the Controllers, Zend will look for a file with the same name as the
action that’s called (in the folder with the same name as the Controller that’s called (in
the “Script” folder)). So if you call http://localhost/users/view zend will execute the
‘viewAction’ in the ‘UsersController’ and when the ‘viewAction’ renders the view, zend
will open the view.phtml file.


The Model

A model represents the database model. In our example we created the model
“users.php”. This class inherits from the ‘Zend_Db_Table’ class. It has one constant
‘$_name’ which represent the name of the table in the database. The initial connection to
the database was made in index.php.

Now, we can use this model in our controllers. I suggest you look at the ‘addAction’ in
the ‘UsersController’ to get started.

More Related Content

What's hot

LvivPy - Flask in details
LvivPy - Flask in detailsLvivPy - Flask in details
LvivPy - Flask in detailsMax Klymyshyn
 
Introduction to Apache Ant
Introduction to Apache AntIntroduction to Apache Ant
Introduction to Apache AntShih-Hsiang Lin
 
Apache ant
Apache antApache ant
Apache antkoniik
 
20130528 solution linux_frousseau_nopain_webdev
20130528 solution linux_frousseau_nopain_webdev20130528 solution linux_frousseau_nopain_webdev
20130528 solution linux_frousseau_nopain_webdevFrank Rousseau
 
Automated Testing with Ruby
Automated Testing with RubyAutomated Testing with Ruby
Automated Testing with RubyKeith Pitty
 
CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkCodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkBo-Yi Wu
 
Puppet for Java developers - JavaZone NO 2012
Puppet for Java developers - JavaZone NO 2012Puppet for Java developers - JavaZone NO 2012
Puppet for Java developers - JavaZone NO 2012Carlos Sanchez
 
Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...
Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...
Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...Ryan Weaver
 
Custom module and theme development in Drupal7
Custom module and theme development in Drupal7Custom module and theme development in Drupal7
Custom module and theme development in Drupal7marif4pk
 
Intro to drupal_7_architecture
Intro to drupal_7_architectureIntro to drupal_7_architecture
Intro to drupal_7_architectureHai Vo Hoang
 
Connect2017 DEV-1550 Why Java 8? Or, What's a Lambda?
Connect2017 DEV-1550 Why Java 8? Or, What's a Lambda?Connect2017 DEV-1550 Why Java 8? Or, What's a Lambda?
Connect2017 DEV-1550 Why Java 8? Or, What's a Lambda?Julian Robichaux
 
Servlet/JSP course chapter 1: Introduction to servlets
Servlet/JSP course chapter 1: Introduction to servletsServlet/JSP course chapter 1: Introduction to servlets
Servlet/JSP course chapter 1: Introduction to servletsJavaEE Trainers
 

What's hot (17)

LvivPy - Flask in details
LvivPy - Flask in detailsLvivPy - Flask in details
LvivPy - Flask in details
 
Introduction to Apache Ant
Introduction to Apache AntIntroduction to Apache Ant
Introduction to Apache Ant
 
Apache ant
Apache antApache ant
Apache ant
 
20130528 solution linux_frousseau_nopain_webdev
20130528 solution linux_frousseau_nopain_webdev20130528 solution linux_frousseau_nopain_webdev
20130528 solution linux_frousseau_nopain_webdev
 
Automated Testing with Ruby
Automated Testing with RubyAutomated Testing with Ruby
Automated Testing with Ruby
 
CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkCodeIgniter PHP MVC Framework
CodeIgniter PHP MVC Framework
 
Java Server Faces
Java Server FacesJava Server Faces
Java Server Faces
 
Puppet for Java developers - JavaZone NO 2012
Puppet for Java developers - JavaZone NO 2012Puppet for Java developers - JavaZone NO 2012
Puppet for Java developers - JavaZone NO 2012
 
Ant
AntAnt
Ant
 
Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...
Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...
Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...
 
BPMS1
BPMS1BPMS1
BPMS1
 
Zend
ZendZend
Zend
 
Custom module and theme development in Drupal7
Custom module and theme development in Drupal7Custom module and theme development in Drupal7
Custom module and theme development in Drupal7
 
Intro to drupal_7_architecture
Intro to drupal_7_architectureIntro to drupal_7_architecture
Intro to drupal_7_architecture
 
Connect2017 DEV-1550 Why Java 8? Or, What's a Lambda?
Connect2017 DEV-1550 Why Java 8? Or, What's a Lambda?Connect2017 DEV-1550 Why Java 8? Or, What's a Lambda?
Connect2017 DEV-1550 Why Java 8? Or, What's a Lambda?
 
Servlet/JSP course chapter 1: Introduction to servlets
Servlet/JSP course chapter 1: Introduction to servletsServlet/JSP course chapter 1: Introduction to servlets
Servlet/JSP course chapter 1: Introduction to servlets
 
JEE Programming - 04 Java Servlets
JEE Programming - 04 Java ServletsJEE Programming - 04 Java Servlets
JEE Programming - 04 Java Servlets
 

Viewers also liked

7 deadly sins in marketing
7 deadly sins in marketing7 deadly sins in marketing
7 deadly sins in marketingTuan Anh Nguyen
 
Owi presentation to rotaract
Owi presentation to rotaractOwi presentation to rotaract
Owi presentation to rotaractStephen Chiunjira
 
ChinasLargestCorpReport2009
ChinasLargestCorpReport2009ChinasLargestCorpReport2009
ChinasLargestCorpReport2009Owen B. Brewer
 
Help Growing Trees Grow Stronger After a Storm
Help Growing Trees Grow Stronger After a StormHelp Growing Trees Grow Stronger After a Storm
Help Growing Trees Grow Stronger After a StormRebekah Black
 
Promo Shops Promotional And Marketing Services
Promo Shops  Promotional And  Marketing ServicesPromo Shops  Promotional And  Marketing Services
Promo Shops Promotional And Marketing ServicesMCrosby
 
Open Access Advocacy
Open Access AdvocacyOpen Access Advocacy
Open Access AdvocacySridhar Gutam
 
How to get a domain name using FatCow.com
How to get a domain name using FatCow.comHow to get a domain name using FatCow.com
How to get a domain name using FatCow.comulee007
 
Naturaleza y-evbolucion-de-la-tecnologia
Naturaleza y-evbolucion-de-la-tecnologiaNaturaleza y-evbolucion-de-la-tecnologia
Naturaleza y-evbolucion-de-la-tecnologiasantiago cisneros
 
Social Media voor het MKB
Social Media voor het MKBSocial Media voor het MKB
Social Media voor het MKBGewoon Groen
 
New Zeeland 22 0 Lecointe
New Zeeland 22 0 LecointeNew Zeeland 22 0 Lecointe
New Zeeland 22 0 LecointeMireia Buchaca
 
A Sustainable Waste Oil Solution
A Sustainable Waste Oil SolutionA Sustainable Waste Oil Solution
A Sustainable Waste Oil SolutionSanskrit44
 
I F E E L D O Y O U D R
I  F E E L  D O  Y O U  D RI  F E E L  D O  Y O U  D R
I F E E L D O Y O U D Rbanothkishan
 
1 8 Landscape Business Taxes & Licenses
1 8 Landscape Business Taxes & Licenses1 8 Landscape Business Taxes & Licenses
1 8 Landscape Business Taxes & LicensesFauquier Horticulture
 

Viewers also liked (18)

1 George
1 George1 George
1 George
 
7 deadly sins in marketing
7 deadly sins in marketing7 deadly sins in marketing
7 deadly sins in marketing
 
Owi presentation to rotaract
Owi presentation to rotaractOwi presentation to rotaract
Owi presentation to rotaract
 
Elaboracion de un blog
Elaboracion de un blogElaboracion de un blog
Elaboracion de un blog
 
ChinasLargestCorpReport2009
ChinasLargestCorpReport2009ChinasLargestCorpReport2009
ChinasLargestCorpReport2009
 
ман
 ман ман
ман
 
Help Growing Trees Grow Stronger After a Storm
Help Growing Trees Grow Stronger After a StormHelp Growing Trees Grow Stronger After a Storm
Help Growing Trees Grow Stronger After a Storm
 
Promo Shops Promotional And Marketing Services
Promo Shops  Promotional And  Marketing ServicesPromo Shops  Promotional And  Marketing Services
Promo Shops Promotional And Marketing Services
 
Open Access Advocacy
Open Access AdvocacyOpen Access Advocacy
Open Access Advocacy
 
How to get a domain name using FatCow.com
How to get a domain name using FatCow.comHow to get a domain name using FatCow.com
How to get a domain name using FatCow.com
 
Naturaleza y-evbolucion-de-la-tecnologia
Naturaleza y-evbolucion-de-la-tecnologiaNaturaleza y-evbolucion-de-la-tecnologia
Naturaleza y-evbolucion-de-la-tecnologia
 
Social Media voor het MKB
Social Media voor het MKBSocial Media voor het MKB
Social Media voor het MKB
 
New Zeeland 22 0 Lecointe
New Zeeland 22 0 LecointeNew Zeeland 22 0 Lecointe
New Zeeland 22 0 Lecointe
 
A Sustainable Waste Oil Solution
A Sustainable Waste Oil SolutionA Sustainable Waste Oil Solution
A Sustainable Waste Oil Solution
 
I F E E L D O Y O U D R
I  F E E L  D O  Y O U  D RI  F E E L  D O  Y O U  D R
I F E E L D O Y O U D R
 
INLS890_ProjectPlan
INLS890_ProjectPlanINLS890_ProjectPlan
INLS890_ProjectPlan
 
El incienso de_la_alabanza
El incienso de_la_alabanzaEl incienso de_la_alabanza
El incienso de_la_alabanza
 
1 8 Landscape Business Taxes & Licenses
1 8 Landscape Business Taxes & Licenses1 8 Landscape Business Taxes & Licenses
1 8 Landscape Business Taxes & Licenses
 

Similar to php-and-zend-framework-getting-started

Getting started-with-zend-framework
Getting started-with-zend-frameworkGetting started-with-zend-framework
Getting started-with-zend-frameworkMarcelo da Rocha
 
Getting started-with-zend-framework
Getting started-with-zend-frameworkGetting started-with-zend-framework
Getting started-with-zend-frameworkNilesh Bangar
 
Maven: Managing Software Projects for Repeatable Results
Maven: Managing Software Projects for Repeatable ResultsMaven: Managing Software Projects for Repeatable Results
Maven: Managing Software Projects for Repeatable ResultsSteve Keener
 
Drupal theming training
Drupal theming trainingDrupal theming training
Drupal theming trainingdropsolid
 
Introduction to Drupal - Installation, Anatomy, Terminologies
Introduction to Drupal - Installation, Anatomy, TerminologiesIntroduction to Drupal - Installation, Anatomy, Terminologies
Introduction to Drupal - Installation, Anatomy, TerminologiesGerald Villorente
 
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_ToolGordon Forsythe
 
How to? Drupal developer toolkit. Dennis Povshedny.
How to? Drupal developer toolkit. Dennis Povshedny.How to? Drupal developer toolkit. Dennis Povshedny.
How to? Drupal developer toolkit. Dennis Povshedny.DrupalCampDN
 
Wamp & LAMP - Installation and Configuration
Wamp & LAMP - Installation and ConfigurationWamp & LAMP - Installation and Configuration
Wamp & LAMP - Installation and ConfigurationChetan Soni
 
Plug in development
Plug in developmentPlug in development
Plug in developmentLucky Ali
 
Mantis Installation for Windows Box
Mantis Installation for Windows BoxMantis Installation for Windows Box
Mantis Installation for Windows Boxguest34a3a419
 
Mantis Installation for Windows Box
Mantis Installation for Windows BoxMantis Installation for Windows Box
Mantis Installation for Windows BoxJayanta Dash
 
Behavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWestBehavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWestJoshua Warren
 

Similar to php-and-zend-framework-getting-started (20)

Getting started-with-zend-framework
Getting started-with-zend-frameworkGetting started-with-zend-framework
Getting started-with-zend-framework
 
Getting started-with-zend-framework
Getting started-with-zend-frameworkGetting started-with-zend-framework
Getting started-with-zend-framework
 
Maven: Managing Software Projects for Repeatable Results
Maven: Managing Software Projects for Repeatable ResultsMaven: Managing Software Projects for Repeatable Results
Maven: Managing Software Projects for Repeatable Results
 
Drupal theming training
Drupal theming trainingDrupal theming training
Drupal theming training
 
Introduction to Drupal - Installation, Anatomy, Terminologies
Introduction to Drupal - Installation, Anatomy, TerminologiesIntroduction to Drupal - Installation, Anatomy, Terminologies
Introduction to Drupal - Installation, Anatomy, Terminologies
 
Fame
FameFame
Fame
 
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
 
How to? Drupal developer toolkit. Dennis Povshedny.
How to? Drupal developer toolkit. Dennis Povshedny.How to? Drupal developer toolkit. Dennis Povshedny.
How to? Drupal developer toolkit. Dennis Povshedny.
 
Wamp & LAMP - Installation and Configuration
Wamp & LAMP - Installation and ConfigurationWamp & LAMP - Installation and Configuration
Wamp & LAMP - Installation and Configuration
 
Plug in development
Plug in developmentPlug in development
Plug in development
 
Drupal development
Drupal development Drupal development
Drupal development
 
Drupal
DrupalDrupal
Drupal
 
instaling
instalinginstaling
instaling
 
instaling
instalinginstaling
instaling
 
instaling
instalinginstaling
instaling
 
instaling
instalinginstaling
instaling
 
Mantis Installation for Windows Box
Mantis Installation for Windows BoxMantis Installation for Windows Box
Mantis Installation for Windows Box
 
Mantis Installation for Windows Box
Mantis Installation for Windows BoxMantis Installation for Windows Box
Mantis Installation for Windows Box
 
Behavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWestBehavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWest
 
Introduction to Zend Framework
Introduction to Zend FrameworkIntroduction to Zend Framework
Introduction to Zend Framework
 

More from tutorialsruby

&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>tutorialsruby
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheetstutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheetstutorialsruby
 

More from tutorialsruby (20)

&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
CSS
CSSCSS
CSS
 
CSS
CSSCSS
CSS
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 

Recently uploaded

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 

Recently uploaded (20)

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 

php-and-zend-framework-getting-started

  • 1. PHP & Zend Framework Tutorial I did a lot of googling, installing, re-installing, … but finally got my first php project to work. I used WAMP for the apache install, the Zend Framework as an MVC, and PostGreSQL as a backend database. Below you can find a basic tutorial on how to get started. Included are following steps: 1. Install & configure WAMP 2. Configure PHP 3. Install & configure PostGres 4. Set up the Zend Framework 5. Start programming I’m gonna try to keep everything as simple as possible. Downside is that you’ll have to try & configure some things on your own. On the other hand it’ll keep this tutorial from becoming too big (and you probably didn’t even got to reading this sentence)… Oh yeah, I’m doing this on my Windows XP system, I don’t know how differently all of this should be done on other systems. 1. Install & configure WAMP. Why WAMP? Well it’s the Windows version of the popular LAMP distribution and the installer configures a lot of things for you. I started with installing & configuring everything (Apache, MySQL/PostGres & PHP) separately which worked (after some time), but I want to spare you the frustrations I had to endure. I’m not gonna tell you how to download it and click next during the installer. The most important thing is the ‘httpd.conf’-file which configures the server. Following parameters are quite important (but should be set correctly after installing WAMP): - the parameter “documentRoot” points to your ‘www’-folder, where you can drop your PHP-files that can be viewed by browser when the server’s URL is given - the parameter “loadModule” points to the PHP configuration that should be used (PHP runtime environment normally is a separate install – Apache can’t handle PHP on his own) Important! I installed WAMP in my “program files” folder, so I recommend you do this too, otherwise you will have to adjust the php.ini file, which is discussed later. So, normally no configuration is need, and after installing you should see an “It works!” when you browse to your http://localhost. If you are having problems, make sure all service are running. 2. Configure PHP
  • 2. The WAMP install will do a lot for you, but you will still have to set your system variables: - Path: add your php folder (e.g: …existingPathValues…;C:Program Fileswampphp) - PHPRC (=PHP Runtime Conf): e.g. “C:Program Fileswampphp” You can google if you don’t know how to set system variables, but remember to restart your PC after having done this. A very important file is php.ini! It configures your PHP runtime environment. I’ll list the most important parameters (to me): (remember to remove the “;” in front of a parameter to uncomment it) - display_errors: set it to “On” - display_startup_errors: set it to “On” - log_errors: set it to “On” (this is good for a dev environment but remember it affects performance) - extension=… (to add dll’s – we’ll need some to connect to PostGres, so I’ll come back to it later) - extension_dir: to tell PHP where it can find dll’s that are added through the ‘extension’ parameters - include_path: used to include external (php-)classes that can be used in your project (we’ll include the Zend framework classes, so I’ll come back to this later) Also something nice is PDO, when learning PHP you’ll stumble on to this – give it some extra attention! 3. Install & configure PostGres Why PostGres? Well, because we’re going to need it for a client. We’ll have an expert setting it up, but it always to know a little bit about what (or who) you are ‘doing’. Normally I would have gone for MySQL (which is part of and configured by WAMP). I suggest you follow the installer. Then open PgAdminIII (part of the installer) and double-click on your server. Enter your password (the one you entered during install) , right-click on ‘databases’ and select “New database…”. For this tutorial enter “firstphpdb” for the name and click “OK”. Then goto ‘Tools’ in the menu and select ‘Query tool’. Enter the following query: CREATE TABLE users ( id serial PRIMARY KEY, firstname varchar(50) UNIQUE NOT NULL, lastname varchar(50) UNIQUE NOT NULL, dateCreated timestamp DEFAULT current_timestamp );
  • 3. Then click the ‘Run’ button. This will create the “Users” table for you (under Schema’s Public Tables). I guess you can find out on your how to enter some names in there. This cheat sheet is quite useful. 4. Set up the Zend Framework OK, why Zend? Well it’s quite popular and IBM also likes it. Since I’m a big fan of Lotus Notes I’ll follow IBM on this. I’ll leave the discussion on which framework to use to the real PHP freaks. First, we need to make sure we can use the Zend classes. We do this in our php.ini through the ‘include_path’ parameter: ; Windows: "path1;path2" include_path = ".;C:Program FilesZendZendFramework-1.0.1library" Of course this setting depend on where you extracted your Zend Framework. Don’t forget to download it. Secondly, you’ll need to understand how it works and should be used. I’ll just explain the MVC setup, but Zend can do much more (I haven’t tried the other features, I’ll probably some more when I do). I’ll try to explain the MVC on a step-by-step basis: 1. Remove everything from you document root (the www-folder of your WAMP installation). First we’re going to create an .htaccess file in this folder. This file… Tip: You can’t create a file that starts with a dot in Explorer, use the “Save as…” function in Notepad. 2. Now, we’ll create an index.php file and drop it in our root folder (the www-folder of your WAMP installation). This file will launch when users browse to your server. You can find the file here. Everything is explained in the file itself: <?php try { // full error reporting (you can actually omit this because we also set this in php.ini) error_reporting(E_ALL); //includes: (remember the include_path in your php.ini? it’s used here) include_once('Zend/Loader.php'); //load the classes //the following translates into 'include(Zend/Controller/Front.php)' Zend_Loader::loadClass('Zend_Controller_Front'); Zend_Loader::loadClass('Zend_Db'); Zend_Loader::loadClass('Zend_Db_Table'); //configure the database $options = array( 'host' => 'localhost' ,
  • 4. 'username' => 'postgres' , 'password' => 'lotusnotes' , 'dbname' => 'firstphpdb' ); $db = Zend_Db::factory( 'PDO_PGSQL' , $options ); //Using Zend_Db_Table is not mandatory, //But it will help write models because it assists in 'fast-writing' sql-queries //If we omit Zend_Db_Table we should use the PDO model Zend_Db_Table::setDefaultAdapter( $db ); //configure the front controller (everything start here!) $controller = Zend_Controller_Front::getInstance(); $controller->setControllerDirectory( './FirstPHPProject/controllers'); //disable automatic view rendering (important, but look at Zend docs for the explanation) $controller->setParam('noViewRenderer' , true); //run the controller $controller->dispatch(); } catch (Exception $e) { echo $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine() . "n"; } 3. Now, because of the Zend_Controller in the index.php file, we need to create a directory structure for our project that the Zend_Controller can use. It is very important that you create it exactly like the Zend framework wants it: The Zend_Controller will translate the url’s that are used. E.g. if you enter “localhost/index/index, Zend_Controller will look for the ‘indexAction’ in the ‘IndexController’ class in the controllers directory. If you enter “localhost/users/view”, it will look for the ‘viewAction’ in the ‘UsersController’. Now, you can ignore the “.cache” and “.settings” folder. Because I’m using Eclipse PDT as an editor, Eclipse created these folders. You can’t see the files, but .htaccess and index.php are at the same level as the folder “FirstPHPProject” and “public”. Now it’s up to you to create the same folder structure. 4. I hope you already know the basics of an MVC framework, because I’m not going to explain it. I’m just going to list the files you should create in each folder and explain some thing in the files themselves in the next chapter…
  • 5. 7. Start programming Is started of using the Zend Editor, which is very nice, but Sven Dens recommended using the Eclipse PDT plugin which has recently got it’s first 1-release. Since I’ve already used Eclipse and this is becoming our company ‘standard’ I went with it. So for no problems… You can find my entire www-folder in the post, so I suggest you download it. This is how it should look like (left is in Eclipse, right in Zend Editor): Most explanations are found in the files themselves. I’ll discuss the basics here.
  • 6. The Controllers As mentioned before, the Zend_Controller handles the requests and translates them into ‘actions’ from ‘controller’ classes in the “Controllers” folder. Let’s take the ‘contactAction’ ‘IndexController’ as an example which we can call through http://localhost/index/contact. The ‘init()’ function as called every time an instance of the IndexController is created. In here, we initialize the view (which we will render at the end of the the ‘contactAction’). We don’t need to specify which view to use: Zend will look for a file called contact.phtml (=action name + .phtml) the in the “index” directory (=controller name) in the “scripts” folder. So make sure it exists. Note that everything is case sensitive! Note: if you omit something, Zend will default to ‘index’. E.g. if you enter http://localhost is will translate to http://localhost/index/index. If you enter http://localhost/users is will translate to http://localhost/users/index. The Views As mentioned in the Controllers, Zend will look for a file with the same name as the action that’s called (in the folder with the same name as the Controller that’s called (in the “Script” folder)). So if you call http://localhost/users/view zend will execute the ‘viewAction’ in the ‘UsersController’ and when the ‘viewAction’ renders the view, zend will open the view.phtml file. The Model A model represents the database model. In our example we created the model “users.php”. This class inherits from the ‘Zend_Db_Table’ class. It has one constant ‘$_name’ which represent the name of the table in the database. The initial connection to the database was made in index.php. Now, we can use this model in our controllers. I suggest you look at the ‘addAction’ in the ‘UsersController’ to get started.