Programmer's Reference Guide

Zend Framework Quick Start

Zend Framework & MVC Introduction

Zend Framework

Zend Framework is an open source, object oriented web application framework for PHP 5. Zend Framework is often called a 'component library', because it has many loosely coupled components that you can use more or less independently. But Zend Framework also provides an advanced Model-View-Controller (MVC) implementation that can be used to establish a basic structure for your Zend Framework applications. A full list of Zend Framework components along with short descriptions may be found in the » components overview. This QuickStart will introduce you to some of Zend Framework's most commonly used components, including Zend_Controller, Zend_Layout, Zend_Config, Zend_Db, Zend_Db_Table, Zend_Registry, along with a few view helpers.

Using these components, we will build a simple database-driven guest book application within minutes. The complete source code for this application is available in the following archives:

Model-View-Controller

So what exactly is this MVC pattern everyone keeps talking about, and why should you care? MVC is much more than just a three-letter acronym (TLA) that you can whip out anytime you want to sound smart; it has become something of a standard in the design of modern web applications. And for good reason. Most web application code falls under one of the following three categories: presentation, business logic, and data access. The MVC pattern models this separation of concerns well. The end result is that your presentation code can be consolidated in one part of your application with your business logic in another and your data access code in yet another. Many developers have found this well-defined separation indispensable for keeping their code organized, especially when more than one developer is working on the same application.

Note: More Information
Let's break down the pattern and take a look at the individual pieces:

learning.quickstart.intro.mvc.png

  • Model - This is the part of your application that defines its basic functionality behind a set of abstractions. Data access routines and some business logic can be defined in the model.

  • View - Views define exactly what is presented to the user. Usually controllers pass data to each view to render in some format. Views will often collect data from the user, as well. This is where you're likely to find HTML markup in your MVC applications.

  • Controller - Controllers bind the whole pattern together. They manipulate models, decide which view to display based on the user's request and other factors, pass along the data that each view will need, or hand off control to another controller entirely. Most MVC experts recommend » keeping controllers as skinny as possible.

Of course there is » more to be said about this critical pattern, but this should give you enough background to understand the guestbook application we'll be building.


Zend Framework Quick Start

Comments

galera
please can someone get me the main info on how to start and finish ZEND framework setup.most especially deatail documentations.

Regards,
Try this: http://akrabat.com/zend-framework-tutorial
The following zend framework quickstart tutorial companion is specific to windows users with a wamp server and who are following the quickstart tutorial as it appears on the official zend site (http://framework.zend.com).

While the zend framework quickstart is the best place to introduce yourself to zend framework, you may have discovered that it doesn't actually work out-of-the-box (especially for windows users). after going through the pain of completing the tutorial, I thought it would be kind of me to go back with a fresh windows system and address all the errors that occur with an out-of-the-box setup. So i reset any changes made to windows, uninstalled all my wamp and zend files and started again.
Below you can see how i addressed all the issues that occurred while following the quickstart tutorial. Hope it helps!

You will probably want a code editor to view some of the necessary files, rather than notepad. I use PSPad editor. it's free and works well.

Also note that if you choose a different directory structure than mine, you will have to update the paths used here according to your setup.

Version Information:

WampServer 2.0i [07/11/09]
Includes :
- Apache 2.2.11
- MySQL 5.1.36
- PHP 5.3.0

Zend Framework 1.10.3

OS: windows xp sp3

Directory Structure:

c:\wamp\(out of the box wamp 2.0 structure)
c:\zend\(out of the box zend framework 1.10.3 structure)
C:\zendSites\(this is the folder i created to hold my zend projects)

-----------------------

Error 1 occurred while trying to create my project from the command prompt.
This error occurrs becuase windows does not know where to look for zf.bat.

C:\zendSites>zf create project quickstart
'zf' is not recognized as an internal or external command, operable program or batch file.

action: add the zf.bat path to windows xp environment variables...
right click mycomputer>>properties>>advanced>>environment variables>>
then highlight "path" in the list of system variables and click edit
in my case i added ";c:\zend\bin" (without quotes) to the end of the list
note that the leading semicolen is the path separator.
restart computer.

--------------------

Error 2 occurred while trying to create my project from the command prompt and after adding the zf.bat path to windows environment variables. This error occurrs because windows does not know how to execute php scripts. It needs to know the path to php.exe

C:\zendSites>zf create project quickstart
'"php.exe"' is not recognized as an internal or external command,
operable program or batch file.

action: add the php.exe path to the windows environment variables.
same as above, but this time i'm adding the path ;C:\wamp\bin\php\php5.3.0
don't forget to restart your computer

--------------------

Expanded explanation of creating a virtual host on windows running wamp server 2.0

open httpd.conf (click on the wamp icon in the services>>apache>>httpd.conf)
find and uncomment the line: #Include conf/extra/httpd-vhosts.conf by removing the # sign go to C:\wamp\bin\apache\Apache2.2.11\conf\extra\ and open httpd-vhosts.conf note the "Apache2.2.11" in the above path. obviously this is version specific.

add the following block of code to the end of httpd-vhosts.conf...

<VirtualHost *:80>
DocumentRoot "c:\zendSites\quickstart\public"
ServerName quickstart.local
SetEnv APPLICATION_ENV "development"
<Directory c:\zendSites\quickstart\public>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

<VirtualHost *:80>
DocumentRoot C:\wamp\www
ServerName localhost
</VirtualHost>

...after adding this block of code you will need to update your windows hosts file, which maps requested urls to the server. go to C:\WINDOWS\system32\drivers\etc and open the hosts file. add the following 2 lines to the bottom of the file...

127.0.0.1 localhost
127.0.0.1 quickstart.local

...now restart your wamp server.

notice the entries for localhost. this is to preserve localhost paths like that for phpmyadmin
note, that now you have done this your address will be quickstart.local so any reference in the tutorial that says to go to http://localhost should be replaced now by http://quickstart.local
this page will not be found by requests outside the local computer. ie. you will not be online until you register with a DNS (beyond the scope of this material)

-------------------------

Error 3
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

after making the changes above you will likely get this error In this case the error is caused becuase appache does not have the rewrite module enabled
action:
click on the wamp server icon in the services portion of the windows task bar.
apache>>apache modules>>scroll down to "rewrite_module" and click it.
wamp should restart automatically

----------------------------

Error 4
Warning: require_once(Zend/Application.php) [function.require-once]: failed to open stream: No such file or directory in C:\zendSites\quickstart\public\index.php on line 18
Fatal error: require_once() [function.require]: Failed opening required 'Zend/Application.php' (include_path='C:\zendSites\quickstart\library;.;C:\php5\pear') in C:\zendSites\quickstart\public\index.php on line 18

at this point if you have not set your include_path in php.ini you will recieve the above error.

action:
click the wamp server icon in the services section of the windows taskbar>>php>>php.ini
now change the following section...

; Windows: "\path1;\path2"
; include_path = ".;c:\php\includes"

to...

; Windows: "\path1;\path2"
include_path = ".;c:\php\includes;c:\zend\library"

...and restart the wamp server again


-----------------------------
Error 5
'dbname' is not recognized as an internal or external command,
operable program or batch file.

cmd input/output:
C:\zendSites\quickstart>zf configure db-adapter 'adapter=PDO_SQLITE&dbname=APPLICATION_PATH "/../data/db/guestbook.db"' production
A db configuration for the production section has been written to the application config file.
'dbname' is not recognized as an internal or external command,
operable program or batch file.

this has to do with the difference between how linux and windows systems intrepret quotation marks.
so you will need to change...

zf configure db-adapter 'adapter=PDO_SQLITE&dbname=APPLICATION_PATH "/../data/db/guestbook.db"' production

to...

zf configure db-adapter "adapter=PDO_SQLITE&dbname=APPLICATION_PATH '/../data/db/guestbook.db'" production

--------------------------------

when creating load.sqlite.php, data.sqlite, schema.sqlite.sql make sure that the scripts folder that holds them is at the same level as the application folder. ie. c:\zendSites\quickstart\scripts
also make sure that the load.sqlite.php code from framework.zend.com is enclosed with the php tags (<?php ?>). when you run this script from the prompt make sure you run it from the quickstart path

--------------------------------

Error 6
C:\zendSites\quickstart>php scripts\load.sqlite.php --withdata
PHP Warning: require_once(Zend/Loader/Autoloader.php): failed to open stream: No such file or directory in C:\zendSites\quickstart\scripts\load.sqlite.php

this was a tricky one. It occurrs when we try to run the load.sqlite.php script because the command prompt uses a different php.ini than apache. you need to navigate to...

C:\wamp\bin\php\php5.3.0\php.ini

now change the following section...

; Windows: "\path1;\path2"
; include_path = ".;c:\php\includes"

to...

; Windows: "\path1;\path2"
include_path = ".;c:\php\includes;c:\zend\library"

...and restart the wamp server again

------------------------------------

after working through all the above issues my quickstart application worked.

Good Luck!
how should i start to read zend.please provide us detail
Are you kidding me? Is this a joke? Why would the entire Zend Framework not install this while it was loaded? I downloaded this free trial to discover whether the zendstudio would HELP speed my web development. I think the answer is clearly - "NO WAY" - when you view the amount of work required to actually make the EXAMPLE PROGRAM work.

Am I completely missing the point here? (BTW, galaera: The fact you posted all of this is quite amazing. Without it, I would have been groping around for hours trying to understand why the system was not working. Can someone from zend explain themselves here? Or, show us where we are wrong and poinit us in the right direction????

What's up with this installation? It seems like you've put a tremendous amount of work into an elaborate IDE and then short circuited on the example setup.
Alstanto:

Thanks for the error resolution. Would you be able to provide the same instructions but instead of using Apache, use IIS?

Thanks for considering.

afh
I am still having problem, I am using wampserver

in windows

I have to type http://localhost/zfpurifyne/public/ in address bar to get the main page to display. Why can't i just type http://localhost/zfpurifyne
[link=http://www.bogartcomputing.com/web-programming-answers/213/a-heavily-corrected-windows-xp-xampp-zend-framework-quickstart-tutorial-revision/]A heavily corrected Windows XP XAMPP Zend Framework Quickstart Tutorial Revision[/link]
A heavily corrected Windows XP XAMPP Zend Framework Quickstart Tutorial Revision

sorry for the repeats, bb code and captcha are holding me up
Zend is a mess...........
I hate this.....
Zend is a mess...........
I hate this.....
I have never seen such a complicated mess. The answer is obvious. They are trying to sell there training sessions. If you noticed they are in the thousands of dollars. There is just no way anyone short of a network engineer could figure this out. It makes me sad, as I long to use the great Zend, but I have already lost days of production trying to figure the whole mess out. I guess I am stuck with Dreamweaver.
If there is a way to setup a server and an editor to build websites, please let me know. As of right now, I can't figure out which Zend I am trying to use, am I using Zend framework, Zend Studio, Zend server? Seriously, it is reallly confusing. I saw hope when I saw the framework stack, but I still can't get the web pages I am building to show on localhost.
Beltnato- still wonderful work on the above explanation.
Why do you figgure you are suck using Dreamweaver it is a far superior product this zend framework is ok adding dojo widgets that really are not that hard to add by hand coding I think that the dreamweaver totaly outclasses Zend Studio and has very simular code help in the newer versions, they finally got class code hints that is all that zend does that is cool besides debuging(I debug by hand anyway!) but it dosn't have Dreamweavers Wysiwyg editor or live preview at at the touch of a button. they are both excellent tools but they are just that tools you can accomplish anything using notepad. and not spend 1000's of dollars. I do agree with everyone that Zend is way too expensive and dosn't do enough for the money that is why I say Dreamweaver OutClasses Zend at about 1/2 the price. Easier to Install Easier to learn.
Why do you figgure you are suck using Dreamweaver it is a far superior product this zend framework is ok adding dojo widgets that really are not that hard to add by hand coding I think that the dreamweaver totaly outclasses Zend Studio and has very simular code help in the newer versions, they finally got class code hints that is all that zend does that is cool besides debuging(I debug by hand anyway!) but it dosn't have Dreamweavers Wysiwyg editor or live preview at at the touch of a button. they are both excellent tools but they are just that tools you can accomplish anything using notepad. and not spend 1000's of dollars. I do agree with everyone that Zend is way too expensive and dosn't do enough for the money that is why I say Dreamweaver OutClasses Zend at about 1/2 the price. Easier to Install Easier to learn.

+ Add A Comment

If you have a JIRA/Crowd account, we suggest you login first before commenting.
  • BBCode is allowed in the comment markup

  • Select a Version

    Languages Available

    Components

    Search the Manual