Art AboutFAQWrite for usContact InfoRSS Feed
Search A/R/T:

Zend Framework Tutorial

by Chris Shiflett — Page 1 of 6
Click to rate:    
1,076 votes / avg. rating 33.42%

We asked PHP security expert — and contributor to the newly-released Zend Framework — Chris Shiflett to write an article for us on the ZF's major features, and he came through with style!

This complete, step-by-step tutorial provides an exclusive first look at building a practical application with the framework by showing you how to write a simple news management system.


 

The Zend Framework has been unveiled! Although it is still in the early stages of development, this tutorial highlights some ofthe best of what's available now and guides you through the process of building a simple application.

Zend has chosen to release the framework and involve the community early. In the same spirit, this tutorial is written to showcase the framework as it exists today. Because this tutorial is published online, I'll update it as the framework evolves, so that it remains relevant as long as possible.

Requirements

The Zend Framework requires PHP 5. In order to take full advantage of the code presented in this tutorial, you also need the Apache web server, because the sample application (a news management system) uses mod_rewrite.

The code from this tutorial is available for free download, so you can try it out for yourself. You can download it from the Brain Bulb web site at http://brainbulb.com/zend-framework-tutorial.tar.gz.

Downloading the Framework

Before you can get started with this tutorial, you need to download the preview release of the framework. You can do this manually by visiting http://framework.zend.com/download with a browser and choosing the tar.gz or zip download, or you can use the command line:

  1. $ wget http://framework.zend.com/download/tgz
  2. $ tar -xvzf ZendFramework-0.1.2.tar.gz
Note

Zend has plans to offer its own PEAR channel to help simplify the download process.

Once you have the preview release, locate the library directory and place it somewhere convenient. In this tutorial, I rename library to lib to provide a clean and simple directory structure:

  1. app/
  2.     views/
  3.     controllers/
  4. www/
  5.     .htaccess
  6.     index.php
  7. lib/
The www directory is the document root, controllers and views are empty directories you'll use later, and the lib directory is from the preview release download.

Getting Started

The first component I want to show you is Zend_Controller. In many ways, it provides the foundation of the application you're developing, and it's also part of what makes the Zend Framework more than just a collection of components. Before you can use it, however, you need to direct all incoming requests to a single PHP script. This tutorial uses mod_rewrite for this purpose.

Using mod_rewrite is an art in itself, but luckily, this particular task is very simple. If you're unfamiliar with mod_rewrite or configuring Apache in general, create a .htaccess file in the document root and add the following directives:

  1. RewriteEngine on
  2. RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php
One of the TODO items for Zend_Controller is to remove the mod_rewrite dependency. In order to provide an example that works with the preview release, this tutorial uses mod_rewrite.
If you add these directives to httpd.conf directly, you must restart the web server. Otherwise, if you use a .htaccess file, you should be good to go. You can quickly test this by placing some identifiable text in index.php and making a request for an arbitrary path, such as /foo/bar. For example, if your host is example.org, request the URL http://example.org/foo/bar.

You also want include_path to include the path to the framework library. You can do this in php.ini, or you can just put the following directive in your .htaccess file:

  1. php_value include_path "/path/to/lib"

Zend

The Zend class contains a collection of static methods that are universally useful. This is the only class you must include manually:

  1. <?php
  2.  
  3. include 'Zend.php';
  4.  
  5. ?>
Once you've included Zend.php, you have access to all of the methods from the Zend class. Loading other classes is simplified with the loadClass() method. For example, to load the Zend_Controller_Front class:

  1. <?php
  2.  
  3. include 'Zend.php';
  4.  
  5. Zend::loadClass('Zend_Controller_Front');
  6.  
  7. ?>
The loadclass() method is include_path-aware, and it also understands the organization and directory structure of the framework. I use it to load all other classes.

 


 Tags:  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
 Add tag(s) (comma separated):
[Tags beta] — [Add New][Help]  

Tags Help

Tags are keywords associated with a web page that help classifying information. You can find a good explanation here.

To add one or more tags to this page, simply enter them below (separate them with a comma) and hit enter or click on the "Go" button.

New Comment
This form allows you to type in a new comment. Keep in mind the following:
  • The system accepts input in plain text format. Newlines will be converted to the HTML equivalent, and the system will try to catch most URLs and make them clickable.
  • Your e-mail address will never be displayed. We will use it only to notify you when new comments are posted to this page.
  • As a rule, we do not delete comments unless they are offensive, racist, spam or otherwise inappropriate.
  • Bold fields are required
Your Name:
Your e-mail:
Type this number:
Subject:
Comment:
Comments   New Comment
Re: Zend Framework Tutorial (#70)
By bavana on 2006-05-25 01:24:14

hi ,

i am trying to learn the Zend framework using the above example.i am stuck up with the foocontroller.php page
..actually this page is not invoking.if i calls the url using foo/bar, it takes the noaction() of the indexcontroller.php ..any idea where i am missing..?

thanks Bavana

[Reply to this]

Re: Re: Zend Framework Tutorial (#126)
By mysticav on 2006-06-10 18:00:48

The problem causing this is because the $_SERVER['REQUEST_URI'] is including a subfolder path that confuse the Router Class.

foe example, if you are running the page on a subfolder like:

[Reply to this]

Re: Re: Zend Framework Tutorial (#299)
By rob on 2006-08-23 13:22:58

This tutorial was good in its own days.

With 0.1.5 release, You should read this tutorial.

http://www.akrabat.com/wp-content/uploads/getting-started-with-the-zend-framework_10.pdf

It's extremely easy to follow and teach very good tips to structure the framework folders.

[Reply to this]

Re: Re: Re: Zend Framework Tutorial (#353)
By Ericx25 on 2006-10-24 15:30:11

Nice tutorial. Too bad it does not work on my PC....

the program tries to open
./application/views\site.tpl.php
while it should look for ./application/views/site.tpl.php

The complete mistake is :

Warning: Zend_View::include() [function.include]: Failed opening './application/views\' for inclusion (include_path='.;./library/;./application/models') in C:\wamp\ www\zf-tutorial\library\Zend\View.php on line 46

[Reply to this]

Re: Re: Re: Re: Zend Framework Tutorial (#585)
By philmee95 on 2007-08-26 06:08:05

He forgot to excplicity tell us to define "PATH_SEPARATOR" in the pdf. That seems to be the problem. I know this is an old post, but I figured somebody may still read it.

[Reply to this]

Re: Re: Re: Re: Re: Zend Framework Tutorial (#592)
By Lex on 2007-09-08 19:40:31

Thanks bro, i read the post and your comment helped me out.

[Reply to this]

Re: Re: Re: Re: Re: Zend Framework Tutorial (#625)
By Joe on 2008-02-18 10:41:33

How do you define "PATH_SEPARATOR" or what site had this information on it?

thanks

[Reply to this]

Re: Zend Framework Tutorial (#71)
By amy on 2006-05-25 03:32:31

Has anyone benchmarked, or tested scalability with this framework, with a large database?

TIA,
http:phpontrax.com

[Reply to this]

Re: Zend Framework Tutorial (#77)
By Varsha on 2006-05-25 16:59:40

Hi !

thanks for the tutorial.My FooController is not working...for whatever action i do I get redirected,my default controller function never gets called..what I need to do.I have followed each step mentioned here carefully..I am having the structure on my localhost...pls help

[Reply to this]

Re: Re: Zend Framework Tutorial (#78)
By BlackSheep on 2006-05-26 02:57:34

Hy,

having had this problem also the last 2 days.

To see what's going wrong just install this script

[Reply to this]

Re: Re: Zend Framework Tutorial (#82)
By Steven Van Poeck on 2006-05-26 17:54:10

If your controller's action is never beeing called, then you most likely have installed the Zend Framwork in a subdirectory of your webserver. You have several options, among which:
1. Patch your copy of Zend_Controller_Router
2. Use your own router, such as Akrabat_Controller_Router (

[Reply to this]

Re: Re: Re: Zend Framework Tutorial (#125)
By rob on 2006-06-10 16:38:08

Sorry, but neither of your 2 suggestions are understandable. Can you explain with more detail ?

what do you mean to "Patch your copy of Zend_Controller_Router" ??

I can't find support for this issue (post #70) on the entire web.

Thanks.

[Reply to this]

Re: Re: Re: Re: Zend Framework Tutorial (#170)
By phparchcoder on 2006-07-06 23:00:15

I had the same problem. You simply need to strip out the sub-directory info in Zend/Controller/Router.php

After line 54:
$path = $_SERVER['REQUEST_URI'];

Put:
$path = str_replace( "my_sub_directory/ www", "", $path );

That's a quick and dirty way to verify that the sub-directory is your problem, and get your test app functioning.

[Reply to this]

Re: Re: Re: Re: Re: Zend Framework Tutorial (#171)
By phparchcoder on 2006-07-06 23:05:28

I don't know how the space before " www" got in the post, but remove that before using the code.

Also, note: I'm refering to line 54 in Router.php, in version 0.1.4 (the latest) of the Zend Framework. (Line number may not be the same in older versions)

[Reply to this]

Re: Zend Framework Tutorial (#81)
By Jim Plush on 2006-05-26 17:50:01

Very nice write up Chris, I was up and running in about 10 minutes. This is my first look at the zend framework and its quite promising so far. Very nice

Jim

[Reply to this]

Re: Zend Framework Tutorial (#100)
By Damian on 2006-05-31 05:39:43

An excellent tutorial, and a very solid framework by the look of things so far.

Well done guys!

[Reply to this]

Re: Zend Framework Tutorial (#109)
By bill on 2006-06-01 21:51:20

A printer friendly version of this tutorial would be a nice touch.

[Reply to this]

Re: Zend Framework Tutorial (#122)
By Hervé on 2006-06-06 12:34:07

A printable version of the full article will be very useful

[Reply to this]

Re: Zend Framework Tutorial (#124)
By rob on 2006-06-10 13:51:15

When I execute foo/bar it calls noRouteAction() method. Even if I execute /index or /index.php the indexAction() is not executed. ALSWAYS THE noRouteAction() is called.

What's hapenning ?


[Reply to this]

Re: Re: Zend Framework Tutorial (#137)
By Gustavo on 2006-06-15 15:33:00

To the guys having problem with subdirectories, so everytime only the noRouteAction() of IndexController is called, try this generic solution:

$url = explode ( "/", $_SERVER['REQUEST_URI']);
$_SERVER['REQUEST_URI'] = str_replace($url[1], "", $_SERVER['REQUEST_URI']);

place it at the first lines of your index.php bootstrap, that may solve the problem in most cases.

[Reply to this]

Re: Re: Re: Zend Framework Tutorial (#173)
By simon r jones on 2006-07-07 08:21:53

In case it's not clear the noRouteAction() issue is occuring because Zend Framework assumes it is being run in the document root of a website. If it is in a subfolder, the translation of the URL to the controller and action will not work.

I've seen a few examples on the web of people patching their version of Zend_Controller_Router if they are using Zend Framework in a sub-directory of their website (as suggested above).

This seems to me a bad idea. Rewriting the REQUEST_URI in the index.php (bootstrap file) seems far simpler.

Gustavo's code will work fine for a single folder depth. For any more I this should work too:

$_SERVER['REQUEST_URI'] = preg_replace('/^' . preg_quote(dirname($_SERVER['PHP_SELF']), '/') . '/', '', $_SERVER['REQUEST_URI']);

This takes the folder index.php is in and then removes this from the server's REQUEST_URI

A more stable solution will be for the ZF itself to natively support running ZF in a subfolder of a site. Which will no doubt happen in the future, and is why rewriting the router seems flawed to me.

[Reply to this]

Re: Re: Re: Re: Zend Framework Tutorial (#174)
By simon r jones on 2006-07-07 08:23:25

that code was all on one line by the way :-)

[Reply to this]

Re: Re: Re: Re: Re: Zend Framework Tutorial (#206)
By simon r jones on 2006-07-12 07:04:54

this is now fixed in Zend Framework 0.1.5 so you shouldn't need to alter any code to get your app working in a sub-folder

[Reply to this]

Re: Re: Re: Re: Re: Re: Zend Framework Tutorial (#265)
By xbaez on 2006-07-31 18:15:31

I already downloaded the ZF 0.1.5 and the problem still there...

[Reply to this]

Re: Re: Re: Zend Framework Tutorial (#272)
By matthew on 2006-08-02 23:22:20

I just implemented this as I've used an apache directory config directive to use a sub-directory of my web root. It works a treat and I'm up and running.

Setts.

[Reply to this]

Re: Zend Framework Tutorial (#138)
By Oliver Saunders on 2006-06-16 13:35:37

I need to modify the RewriteRule slightly as the DocumentRoot I'm using is the result of an Alias. Basically the stuff in the .htaccess is redirecting to "/osis/x/osis/ www/index.php" and I would like it to redirect to "x/osis/ www/index.php" instead, any idea how I could do this with rewrite?

I've looked at the documentation on rewrite and I'd really rather not have to learn it all just to do this.

[Reply to this]

Re: Re: Zend Framework Tutorial (#156)
By Paul Kelly on 2006-06-29 03:06:49

Add a RewriteBase parameter if you're using an alias.
e.g. if I have a directive in httpd.conf:
Alias /foo /var/

[Reply to this]

Re: Zend Framework Tutorial (#159)
By fs on 2006-07-02 05:43:40

To the problem of rewrite:
In http.conf:
1)Load the rewrite module
LoadModule rewrite_module modules/mod_rewrite.so
2) allow to use .htaccess for server root
at <directory /> (that's instructions for root) 'AllowOverride All' (or at least not 'None')
If you are on a rent server I don't know how to check - maybe ask them.

Anybody know how to put index.php in subdir of root?
Regards FS

[Reply to this]

Re: Zend Framework Tutorial (#166)
By kynan on 2006-07-04 09:44:27

Hm. Shouldn't the rewrite be:

RewriteRule !\.(js|ico|gif|jpg|png|css)$ /index.php

note the "/" before the index.php. Without the "/" apache seems to get a bad request on my Mac OS X server. Could be wrong but I thought i'd mention it!

[Reply to this]

Re: Zend Framework Tutorial (#168)
By Panumat on 2006-07-06 06:35:58

This is my app struct ( on Linux Server)
Notice : Windows work well

/
myapp/
application/
controllers/
views/
library/
Zend/

[Reply to this]

Sweeeet! (#181)
By NetBear on 2006-07-07 18:00:35

Thanks for writing such a great tutorial on Zend Framework. It has helped imemnsely! It has just the right amount of detail.

[Reply to this]

Re: Zend Framework Tutorial (#197)
By Panumat on 2006-07-11 04:52:17

Why alias doesn't work (Apache 2.0.xx,Windows XP,-PHP5.1.x)?
I called it like this:
"

[Reply to this]

Re: Re: Zend Framework Tutorial (#198)
By panumat on 2006-07-11 04:55:24

Sory, that missing!!!
I call it like this:

[Reply to this]

Re: Zend Framework Tutorial (#200)
By voidru on 2006-07-11 08:14:07

Hi, that's great tutorial. But I have a question.

How can I send parametres to actions?
In AddController.php I am create simple method:
function testAction($foo)
{
echo $foo;
}

when I am trying to get

[Reply to this]

Re: Re: Zend Framework Tutorial (#202)
By voidru on 2006-07-11 08:20:44

when I am trying to get
h_t_t_p://localhost/zend/add/test/foo/1
browser returns to me this message:
Warning: Missing argument 1 for AddController::testAction() in D:\ www\app\controller\AddController.php on line 38

I am testing ZF from subfolder /zend on my Apache. Router already patched.

What am I doing wrong?
p.s. Sorry for my bad English.

[Reply to this]

[Comment deleted by administrator] (#201)
By voidru on 2006-07-11 08:17:46

This comment was deleted by the system administrator

[Reply to this]

Re: Zend Framework Tutorial (#218)
By jimma on 2006-07-15 11:35:12

When accessing /www/ directory Apache was giving me a 404 error, /mysite/ www/index.php not found..

To fix I had to add a few rewrite conditions to .htaccess:

# .htaccess in /

[Reply to this]

Re: Re: Zend Framework Tutorial (#219)
By jimma on 2006-07-15 11:36:58

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php

[Reply to this]

Re: Re: Re: Zend Framework Tutorial (#220)
By debilul on 2006-07-15 17:18:18

I want to learn php language, where I need begining?

[Reply to this]

Re: Zend Framework Tutorial (#223)
By octix on 2006-07-18 04:28:03

Hi, 10x for this start article, it helped me to setup zf.

But there are some issues that i'm not agree with:

[organization of news management system]

i'm totaly don't agree with add controller, from my point of view add is action and news is the controller, because we can make more actions to news(edit, delete, change stat, etc), will you make all this controllers for news? eg /edit/news /delete/news ? ) i doubt it

[Reply to this]

Re: Re: Zend Framework Tutorial (#273)
By Chris Shiflett on 2006-08-03 00:19:13

I agree with you. The next revision of this tutorial will correct this.

Thanks for the feedback.

[Reply to this]

Re: Zend Framework Tutorial (#274)
By Dying Angel on 2006-08-03 14:10:43

Great Tutorial.

finaly i get a grasp of zf,
and developing a application with it.

and the RewriteRouter rocks !!!
finnaly i can put my application on sub directory

thanks

[Reply to this]

Re: Re: Zend Framework Tutorial (#295)
By rob on 2006-08-23 03:09:26

I patched the router as many have done it in order to work with a subdirectory based website. My first impression was great. Everything seemed to work perfectly.

Until I tried to incorporate javascript libraries and toolkits, like DOJO, wich depend and use the URI.

So, after 0.1.5 release, What's the best solution for this ??

By the wat, does anybody has tried this tutorial under a subdirectory ?:

DOjo with ZF.

http://www.alexatnet.com/Blog/Index/2006-07-26/create-ajax-login-page-with-dojo-toolkit-and-zend-framework

[Reply to this]

Re: Re: Re: Zend Framework Tutorial (#351)
By Alexander on 2006-10-24 02:42:09

Try this one:

Using Zend_Controller in subfolder
http://www.alexatnet.com/Blog/Index/2006-09-26/using-zend_controller-in-subfolder

and this:

How to run a PHP application together with the Zend Framework application
http://www.alexatnet.com/Blog/Index/2006-10-03/how-to-run-a-php-application-together-with-the-zend-framework-application

The second tip you can use when installing dojo toolkit, just add the corresponding folder to the list of RewriteCond before the RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php

[Reply to this]

Re: Zend Framework Tutorial (#275)
By Jonny on 2006-08-04 10:42:34

In Zend Framework version 0.1.5 you have to replace the classname "Zend_InputFilter" with "Zend_Filter_Input".

[Reply to this]

Different rewrite rule (#277)
By Brandon Grady on 2006-08-05 16:37:04

Great tutorial. I'm almost all the way through. It took me several hours to get up and running, however. My problem started with being installed in a sub-directory of the root web directory (actually a virtual directory), which I finally found in the comments of this page.

My more significant problem was with mod_rewrite. I don't know much about it, so I simply followed the directions on this page. When I did that, I got a 500 Internal Server error. When I looked in the error log file, it said something about recursing too many times. When I changed the rule to the following, it worked correctly:

RewriteRule !\.(html|php/js|ico|gif|jpg|png|css)$ /zf/index.php

As you see, I added the subdirectory to the routed file, but also added the html|php strings to the list of file extensions to ignore. This stopped the recursion and I'm up and running now. Can anybody with experience with mod_rewrite think of reasons not to add these documents to my rewrite rule? Is there a reason it might not work on my system the same way it seems to be working on other's systems?

Thanks for the tutorial.

[Reply to this]

Re: Different rewrite rule (#278)
By Dying Angel on 2006-08-07 03:21:27

on sub directory case i use the Zend_Controller_RewriteRouter, so it goes like this :

Zend::loadClass('Zend_Controller_RewriteRouter');
$router = new Zend_Controller_RewriteRouter();
$router->setRewriteBase('/_zend/myApp');

but in my case the image on the view / html is not working on relative path so i have to put absolute path on my image/js/css

does your rewrite rule rewrite the image/js/css too ?

[Reply to this]

a 404 error (#279)
By Ikin on 2006-08-08 06:42:04

Hi all, I'm very new to this...

So I tried exactly as the tutorial above, but when i tried to access arbitrary page, let's say foo.php it will give me a 404 error, saying that index.php is not there!

This is a similar comment to #219 above... #219 actually helps me redirect to index.php from www/, but not www/arbitrarypage.php

I think it's some apache configuration thing... please help :)

Thanks!

[Reply to this]

Re: a 404 error (#282)
By Ikin on 2006-08-08 19:18:51

Nvm, it turns out that it's because the apache docroot is different from where i put the tutorial code in...

[Reply to this]

Re: Zend Framework Tutorial (#286)
By Joselee on 2006-08-14 02:46:46

Has any one tried the tutorials using the Zend Framework Preview 0.1.5, I have followed the tutorial using the ZF 0.1.5 but I get errors "Fatal error: Uncaught exception 'Zend_Controller_Action_Exception' with message 'Cannot redirect because headers have already been sent", please help

[Reply to this]

Re: Re: Zend Framework Tutorial (#307)
By Adam Schlag on 2006-09-01 11:14:50

I ran into that problem myself, until I realized I had output buffering turned on in my php.ini (I use the recommended php.ini and tweak it where necessary).

If you don't have access to (or don't want to change) php.ini, you can set this in .htaccess like so:

php_value output_buffering "4096"

You can change the number to any value you want, or just to "On".

Hope this works for you and anyone else having this problem!

[Reply to this]

Re: Re: Re: Zend Framework Tutorial (#539)
By entragian on 2007-05-22 13:58:08

you saved my life :) thx!!!

[Reply to this]

Re: Zend Framework Tutorial (#288)
By Robert on 2006-08-15 20:07:53

Great tutorial. Only some part aren't right anymore, like Zend_InputFilter, this must be Zend_Filter_Input.

Also when 1 item is waiting for approval the list will be messed up, this is because you use return $result->fetch in your database class.

But overall this was a nice tutorial. I'm really excited about the Zend Framework.

[Reply to this]

Re: Zend Framework Tutorial (#292)
By pyd on 2006-08-18 10:52:14

Thanks a lot for this tutorial. It help me "playing" with zf.
I'm just wondering why, controllers script
work without this line :
require_once 'Zend/Controller/Action.php';
Because of "extends" or the include_path in my php.ini?

thx again

[Reply to this]

Re: Zend Framework Tutorial (#294)
By Joseph Myalla on 2006-08-21 07:41:02

I followed the tutorial using ZF Preview 0.1.5,when I call the urls only the Index Action is called in the IndexContoller.php, other actions are not called, please help

[Reply to this]

Re: Zend Framework Tutorial (#309)
By corentin on 2006-09-03 13:05:44

thanks a lot for this tutorial
this framework is wonderfull !
and it is just the beginning

[Reply to this]

Re: Zend Framework Tutorial (#313)
By San on 2006-09-06 09:15:26


Hi,
Thanks for this tutorial.
In my case the root is working but the other urls are not working :-(
http://localhost/zf_tutorial/ :- WORKING

http://localhost/zf_tutorial/index/add :- NOT WORKING

[Reply to this]

Re: Zend Framework Tutorial (#337)
By reshmi on 2006-10-03 08:13:41

hello,
this tutorial is really a good one.but i want these examples in php4.Could you suggest any site with zend framework and php4.I am supposed to work with php4 and zend framework
Please help me in this regard.
regards
reshmi

[Reply to this]

Re: Re: Zend Framework Tutorial (#340)
By ming on 2006-10-08 12:22:52

Zend Framework only works with PHP5 and up

[Reply to this]

Re: Zend Framework Tutorial (#348)
By Joss on 2006-10-18 08:46:17

Hi,
Thanks for this tutorial.

My case is the same as Sun. the root is working but the other urls are not working :-(
http://localhost/zf_tutorial/ :- WORKING

http://localhost/zf_tutorial/index/add :- NOT WORKING
I just want to add I have an IIS server running and ( of course ) I do not have .ataccess active.

[Reply to this]

Re: Zend Framework Tutorial (#349)
By Joss on 2006-10-22 08:37:14

Finally i have the apache server running after installing PHP5.2 with php5Apache2_2.dl , but i still have a problem with mod_rewrite option.

I have installed zf in a sub-directory of the root web directory which is "C:\Programmi\Apache Software Foundation\Apache2.2\htdocs"
So my structure is :
\htdocs
\zf
.htaccess
index.php
\application
\controllers
\models
\view
\library
\public

exactly as reported in tutorial.
the file .htaccess is :

RewriteEngine on
RewriteRule .* index.php
php_flag magic_quotes_gpc off
php_flag register_globals off

the index.php is :
<?php
phpinfo();
?>
when i go to http://localhost/zf i got a 500 Internal Server error.
When I looked in the error log file, it said something about recursing too many times. this is the error log:
[client 127.0.0.1] r->uri = /zf/index.php
[client 127.0.0.1] redirected from r->uri = /zf/index.php
[client 127.0.0.1] redirected from r->uri = /zf/index.php
[client 127.0.0.1] redirected from r->uri = /zf/index.php
[client 127.0.0.1] redirected from r->uri = /zf/index.php
[client 127.0.0.1] redirected from r->uri = /zf/index.php
[client 127.0.0.1] redirected from r->uri = /zf/index.php
[client 127.0.0.1] redirected from r->uri = /zf/index.php
[client 127.0.0.1] redirected from r->uri = /zf/index.php
[client 127.0.0.1] redirected from r->uri = /zf/index.php
[client 127.0.0.1] redirected from r->uri = /zf/

what am i doing wrong ??
could someone help me. thanks for the feedback.

[Reply to this]

Re: Re: Zend Framework Tutorial (#352)
By Alexander on 2006-10-24 02:56:31

Try the following rule instead of yours:
RewriteRule .* /index.php

[Reply to this]

Re: Zend Framework Tutorial (Feed Problem) (#354)
By Stephanie on 2006-10-31 01:06:20

Can anybody get the feed Slashdot example from the Zend Manual to work? When I run the code the returned Slashdot feed object has no entries (just the channel information). When I use my web browser to look at the RSS feed, there are several entries.

[Reply to this]

Expertise needed for this (#355)
By Brian Jones on 2006-10-31 19:06:44

I guess you have to be something of a web technology expert to use this stuff. www.brianjones.info/blog

<a href=" www.brianjones.info/blog">web technology expert</a>

[Reply to this]

Re: Expertise needed for this (#356)
By Brian Jones on 2006-10-31 19:07:53

Please erase my last comment. I didn't mean for it to turn out that way and I don't want to spam your site.

[Reply to this]

Re: Zend Framework Tutorial (#357)
By someoneWhoUsesFirefox on 2006-11-01 04:27:58

OMG I couldn't believ that such a tutorial was written by lamers like u... just try to copy the code from firefox... its all messed up. i mean if u make a website why not make it for other browsers not just the big dumb IE?

[Reply to this]

Re: Re: Zend Framework Tutorial (#359)
By someoneElseWhoUsesFirefox on 2006-11-05 20:54:00

OMG I couldn't believ that such a tutorial was viewed by a lamer like u... when i try to copy the code from firefox... it works perfectly! i mean if u view a website why not try to take a moment to look over the code examples.

Next time use the damned "Toggle plain text mode" link to turn off the syntax highlighting and then the "Select listing" link to automatically copy it to your clipboard and then PASTE it into your text editor.

This has less to do with MSIE and more to do with another big dumb =E.

[Reply to this]

Re: Zend Framework Tutorial (#366)
By Zubin on 2006-11-20 06:48:38

hi,
I tried listing 5 , but the following errors i got.I also edited php.ini to include the lib.

Warning: include(Zend.php) [function.include]: failed to open stream: No such file or directory in C:\Program Files\xampp\htdocs est\index.php on line 2

Warning: include() [function.include]: Failed opening 'Zend.php' for inclusion (include_path='C:\Program Files\xampp\apache\Zend\library"') in C:\Program Files\xampp\htdocs est\index.php on line 2

[Reply to this]

To #219 (#373)
By fishtrees on 2006-12-03 11:32:21

This is a very useful tutorial. I do it follow tutorial step by step,until I have got "Not Found" problem.

then I saw #219's reply,and
I place following code in my .htaccess in "/":

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php

and my apache2 has loaded mod_rewrite.
but when I request /foo/bar,apache2 tell me "The requested URL /foo was not found on this server."

pls help!!!

my os is windows xp.

[Reply to this]

Getting Doubles of in Zend Controller (#375)
By Xavier on 2006-12-08 23:07:26

Hi,

Nice framework. But I am getting the controller repeated twice. How do I get rid of this.

See example at
http://blog.vietchao.com/
http://th.harro.com/user/register/

Appreciate comments.

Regards,
X

[Reply to this]

Register View to prevent doubles! :) (#377)
By Harro Alive! on 2006-12-11 21:56:06

Hi all, managed to resolve this. Remember to register the view. The tutorial at IBM doesn't tell us this, so Chris, you are ahead. :)

Xavier
http://www.harro.com

[Reply to this]

Re: Zend Framework Tutorial (#427)
By James Bell on 2006-12-27 10:59:32

Screenshots? I'd sure like to see what it makes by default and then what you can do with some basic CSS.

[Reply to this]

Re: Zend Framework Tutorial (#474)
By unknown man on 2007-01-10 03:18:16

assume that you see http://url/module/adction/key/value and can write like this in your action's method:
<?php
class FooController extend Controller_Action_Handler
{
function doAction()
{
$this->plugin->db->insert(array("field","value"),"tblName");
$var = $this->param->var; //return value
$feed = $this->plugin->feed->get("example.rss");
// and more and more capability like
// loading xml base configuration
// for each file automatically &
// you can use it with :
// $this->spec->entry in your
// action class,
// or autoloading template if needed
// and more and more
}
}


i do this in myself framework, i integrate all performance in cakephp, symphony and zend, and make new one. possible that i publish it... what is your idea about this...

[Reply to this]

Re: Zend Framework Tutorial (#479)
By Rosario on 2007-01-29 11:06:54

i have the apache server running PHP5, I have installed the library in a sub-directory of the root web directory

So my structure is :

\htdocs
\cg
.htaccess
index.php
\application
\controllers
\models
\view
\library
\public


the file .htaccess is :


RewriteEngine on
RewriteRule .* /index.php


I have created a controll called IndexController.php which is the controllers folder :




<?php

Zend::loadClass('Zend_Controller_Action');

class IndexController extends Zend_Controller_Action
{
public function indexAction()
{
echo 'IndexController::indexAction()';
}

public function noRouteAction()
{
$this->_redirect('/');
}
}

?>


...and another file called FooController.php



<?php

Zend::loadClass('Zend_Controller_Action');

class FooController extends Zend_Controller_Action
{
public function indexAction()
{
echo 'FooController::indexAction()';
}

public function barAction()
{
echo 'FooController::barAction()';
}
//undefined action
public function __call($action, $arguments)
{
echo 'FooController:__call()';
}
}

?>


When I request /foo/bar the barAction() is not executed....the Browser shows the HTTP 404 error page was not found

Any help.......Thanks

[Reply to this]

Re: Re: Zend Framework Tutorial (#486)
By Erdal on 2007-02-17 04:21:55

Your Apache must read right .htaccess files,because off in http.conf your site directory section must be AllowOverride All.

[Reply to this]

Re: Zend Framework Tutorial (#489)
By Travis Miller on 2007-03-01 16:30:58

Excellent tutorial - everything is explained very clearly. I've been trying to make headway with PHP frameworks, design patterns, and OOP-based architectures for a while now, and your tutorial is one of the best I've found.

However, I'm following your examples, and I've encountered a couple of unexpected behaviors. These may be due to changes in the framework since you last updated the article (I'm using 0.8.0), or my own ineptitude, but I figured I'd point them out:

1. I don't get an error, as described, when trying to access /foo/bar after implementing the code in Listing 8. I just get an empty page.

2. The noRouteAction() function of IndexController (listing 10) isn't triggered as described; again, requests for non-existent actions (e.g., /index/asdf) simply produce an empty page. Requests for /index/noRoute, however, *do* trigger this method.

Other than that, everything is working beautifully.

[Reply to this]

Re: Zend Framework Tutorial (#530)
By Manoj on 2007-04-26 13:45:08

I am new to zend framework

I have created a directory structure as

test_zend/
index.php
.htaccess
app/
view/
controllers/
FooController.php
IndexController.php
lib/

I am trying to run the URL
http://localhost/test_zend/foo/bar

but it gives me the following warning
Warning: Zend_Loader::include_once(app/controllers\FooController.php) [function.Zend-Loader-include-once]: failed to open stream: No such file or directory in C:\wamp\ www est_zend\lib\Zend\Loader.php on line 175

Warning: Zend_Loader::include_once() [function.include]: Failed opening 'app/controllers\FooController.php' for inclusion (include_path='lib/') in C:\wamp\ www est_zend\lib\Zend\Loader.php on line 175

I cannot understand why it gives this warning. Please help me to sort out this problem. Thanks in advance

Manoj

[Reply to this]

Re: Re: Zend Framework Tutorial (#603)
By christof coetzee on 2007-10-17 06:59:29

this is a fix I have come up with that will allow fetchAll to correctly join dependant parent

tables, so that fetchAll in fact bring back all related parent tables as it would in a normal

LEFT JOIN query - the ZPDataJoiner can obviously be refined a lot more.

How to: create a class file from the below and include it in your table model class file, then

instead of extending your table class with Zend_Db_Table_Abstract extend it with ZPDataJoiner,

this will override the fetchAll() of Zend_Db_Table_Abstract.

require_once 'Zend/Db/Table/Abstract.php';

class ZPDataJoiner extends Zend_Db_Table_Abstract{

public function fetchAll($where = null, $order = null, $count = null, $offset = null) {

$select = $this->_db->select();

$select ->from(array('thistable' => $this->_name))
->order($order)
->limit($offset,

$count);

if (!is_null($where)) {
$select->where($where);
}

if (!empty($this->_referenceMap)) {


foreach($this->_referenceMap as $ruleName => $specs) {

if (isset($specs['columns']) && isset($specs['refColumns']) &&

isset($specs['refTableClass'])) {


if(isset($this->parentTables[$specs['refTableClass']])){
// echo $specs['columns'].'<hr>';
$parTable = $this->parentTables[$specs['refTableClass']];
$parAlias = $ruleName;

$select->joinLeft(array($parAlias => $parTable),


'thistable.'.$specs['columns'].' = '.$parAlias.'.'.$specs['refColumns'],array('*'));


}

}

}

}

//$select->toString(); return false;
$stmt = $select->query();


$data = array(
'table' => $this,
'data' => $stmt->fetchAll(Zend_Db::FETCH_ASSOC),
'rowClass' => $this->_rowClass,
'stored' => true
);
//print_r($data['data']);
Zend_Loader::loadClass($this->_rowsetClass);
return new $this->_rowsetClass($data);


}
}

//example model class

class Cities extends ZPDataJoiner{
protected $_primary = array('city_id');
protected $_name = 'cities';
protected $_dependentTables = array('departments','staff');

/*the $parentTables is important array(tableclass=>actual_table_name)
it is used by ZPDataJoiner to resolve relationships
and I was to lazy to write a lookup that could use only the
$_referenceMap
*/
protected $parentTables = array('Countries'=>'countries');

protected $_referenceMap = array(
'CitiesToCountries' => array(
'columns' => 'country_id',
'refTableClass' => 'Countries',
'refColumns' => 'country_id',
'onDelete' => '',
'onUpdate ' => ''
));

}

[Reply to this]

Re: Zend Framework Tutorial (#555)
By matt on 2007-06-16 05:58:37

This tutorial is out-dated. Mr. administrator - You should place a information that this tutorial is no longer valid. Especially because this tutorial is as first item search result when using google.

[Reply to this]

Re: Re: Zend Framework Tutorial (#559)
By JaraJara Brazil on 2007-06-23 11:04:32
Re: Zend Framework Tutorial (#574)
By Swamy on 2007-08-01 08:22:29

Friends,
Could you please explain how to start zend framework implementation or give me simple program.
Because i used to write PHP code without any framework.
I want to learn and implement ZF. If you help it would be benificial to me. Advance thanks for your clarification that you are going to provide.

[Reply to this]

Re: Zend Framework Tutorial (#577)
By Udayakumar on 2007-08-04 08:11:31

I have downloaded the Zendframework 1.0.1 files. But there is no Zend.php file in the library folder of the downloaded file. Please help me anybody. Is that necessary to set-up?

[Reply to this]

Re: Zend Framework Tutorial (#580)
By Valdhor on 2007-08-08 16:30:35

In version 1.0.1 it looks like the Zend.php file is no longer used. In my index.php file I did this...

ini_set('include_path',ini_get('include_path').":/path/to/lib:");
ini_set('include_path',ini_get('include_path').":/path/to/lib/Zend:");

include 'Loader.php';

Zend_Loader::loadClass('Zend_Controller_Front');

[Reply to this]

Re: Re: Zend Framework Tutorial (#595)
By MikeD on 2007-09-22 20:14:28

Valdhor wrote:
ini_set('include_path',ini_get('include_path').":/path/to/lib:");
ini_set('include_path',ini_get('include_path').":/path/to/lib/Zend:");

include 'Loader.php';

Zend_Loader::loadClass('Zend_Controller_Front');

don't really need both paths to point to the lib, but it won't kill you to have them. you could do this instead:

ini_set('include_path', ini_get('include_path') . ":/path/to/lib:");
include 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Controller_Front');

and for windows users change the ini_set to:
ini_get('include_path') . "; c:/path/to/lib;");

[Reply to this]

Re: Zend Framework Tutorial (#601)
By huangam on 2007-10-13 05:05:19

Now, Zend Framework has unveiled the version 1.0.2, but the code here cann't work successfully based on the latest version. Could you update your code?
Thank you!

[Reply to this]

Re: Zend Framework Tutorial (#610)
By Nandhini on 2007-11-03 03:22:08

I had downloaded the Zendframework. I want to learn it.Please any one help me how to install and from where i have to start it

[Reply to this]

Index