Getting Started with Zend Framework 1.11

Screen short of Zend Framework tutorial

This tutorial is intended to give an introduction to using Zend Framework to write a simple database driven application. It has been updated for version 1.10 of the framework and takes full advantage of the Zend_Tool command line script and Zend_Application for bootstrapping. Other components used include Zend_Controller, Zend_View, Zend_Db_Table and Zend_Form.

I have also written a tutorial on Zend_Auth.

This tutorial has been tested on version 1.10 and 1.11 of Zend Framework. It will not work on any version prior to version 1.10.

Tutorial note: If you are getting 404 errors when going to any page other than the home page, please make sure that you have set AllowOverride to All in your Apache configuration and have enabled the mod_rewrite extension.

If you are deploying to a "user" site (e.g. http://localhost/~rob), then you need a RewriteBase line in your .htaccess file that looks something like: RewriteBase /~rob/zf-tutorial/public/.

Download the PDF (v1.7.7)

Translations

Very kindly, these people have provided translations of this tutorial into other languages. Thank you!

Chinese version: Zend Framework 教程. Translated by Leefar.
Italian version: Introduzione allo Zend Framework. Translated by Mario Santagiuliana.
Polish version: Pierwsze kroki z Zend Framework. Translated by Radosław Benkel.
Portuguese version: Iniciando com o Zend Framework. Translated by Gilberto Albino.
Czech version: Začínáme se Zend Frameworkem. Translated by Martin Hujer.
French version: Débuter avec Zend Framework. Translated by Bernard Opic.
Spanish version: Introducción a Zend Framework. Translated by Alejandro Mohamad.

Code

The associated code is available:

Further reading

Once you have finished this tutorial, consider buying my book, Zend Framework in Action. Also, the Quick Start is worth reading.

Chris Kirk has kindly provided a Q&A PDF for the 1.8 version of the tutorial which may help if you are having problems.

Previous versions of this tutorial

There have been three previous versions of this tutorial:

Changelog

1.7.7 (18/Sep/2011)
Typographical fixes
1.7.6 (16/Mar/2011)
Typographical fixes
1.7.5 (3/Oct/2010)
Typographical fixes
1.7.4 (25/Jul/2010)
Move setting the title to the view scripts and use zf create dbtable to create the table class
1.7.3 (29/Jun/2010)
Typographical fixes
1.7.2 (17/Apr/2010)
Typographical fixes and use Zend_Form's init() method
1.7.1 (11/Feb/2010)
Fix code in deleteAction to use the correct model name
1.7.0 (7/Feb/2010)
Significantly revised for Zend Framework 1.10

308 thoughts on “Getting Started with Zend Framework 1.11

  1. Thank you very much, great stuff, again.
    One minor problem in the zip files though:
    IndexController.php line 91 (deleteAction)
    $albums = new Model_DbTable_Albums();
    generates an error
    forgot the 'Application_'?
    greets,
    el mich

  2. You'll better correct the pdf version number and the download link from 1.7.0 to 1.10.0 .

    Regards,
    Italo A.

  3. I'm getting a 'Class 'Application_Model_DbTable_Albums' not found in C:wampwwwzf-tutorialapplicationcontrollersIndexController.php'

    after following up to page 12 of this tutorial!

    Can you help?

  4. I'm new to object-oriented php and Zend Framwork and I found this tutorial very useful, thanks a lot.
    I'm running this on the newest Zend Server CE as a virtual host and it works like a charm. :-)

  5. Error is happeing because class name is wrong
    Solution
    Rename Model_DbTable_Albums to Application_Model_DbTable_Albums in controllers/IndexController.php

  6. I believe the correct location for the layout.phtml file shown on pages 10 and 11 of the tutorial should be:

    zf-tutorial/application/layouts/scripts/layout.phtml

  7. This is the tutorial Zend Framework newbies have been seeking! A complete working project interspersed with useful explanations.

    Very well done, thanks!

    iMac 10.6.2 Snow Leopard
    MacPorts install of Apache, MySQL, PHP and phpMyAdmin.

  8. In your tutorial, the Application_Model_DbTable_Albums class could be created with the zf command line tool:
    'zf create dbtable Albums albums'

  9. Thanks a lot for this tutorial, I was looking for some good and straight to the point explanations to start with Zend and this is pretty good stuff!

  10. Hi again,

    It's been a few days I try to augment and modify this simple application to make a real (but still relatively simple) administration console.

    This is a was also to get more familiar with Zend.

    Sincerely it is a PAIN, when something does not work I just have "Application Error" displayed, or worse, most of the time, a white page!
    Even if I code pure PHP from scratch will I have better indication of what is wrong when there is an error!

    The question would be: where the hell do the error messages go?

    (I am trying to simply upload a picture, rename it and move it to a folder I create on the fly, and resize it. But moving and renaming the file just does not work, and I tried many things I saw in tutorials etc… I am a bit disappointed as I expected this to be basic stuff for zend)

  11. Hi David,
    I guess you are using the "production" setting, which has display_errors = 0. I suggest using the "development" enviroment setting instead.

    check your index.php code
    on line 8.
    // Define application environment
    defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));

  12. Thanks MayorBrain! ok I changed to development, I guess it should be better like this.

    Anyway when I do a echo "string" in the IndexController.php code I never see my "string" displayed when executing the code.. any idea where it goes?

    Also a problem with form is that sometimes I press the submit button and it stays blocked on the page, like if it was loading something forever. I need to press the submit button a second time to have the form processed and go back to the index page. I think it is specific to the file upload I added in the form, and seems to happen when I upload 2 times the same file..
    Has anyone ever seen experienced this?
    As there is absolutely no message displayed (even in development) it is hard to know what is wrong..

    And finally (and I promise I am going to stop here:),
    -What development environnement would you recommand to develop with zend? Is there any way to have autocompletion of some sort, or do we have to look everytime at the manual for each parameters etc.. ?
    I am on mac os, using dreamweaver to edit my php but I am thinking on moving to eclipse with php.
    A tutorial to setup a good working environment for zend development would be awesome!
    -What forum who be the best to adress those kinds of issues specifically with zend?

    Thanks !

  13. I've met the same problem as David. In project created with Zend_Tool only Application Error message is shown without any details. I am sure I've set my APPLICATION_ENV to development. Can this be in case of custom .htaccess file in project directory? It just redirect all queries to /public/ since the baseurl part is not empty.

  14. After 2 weeks with Zend, I found the learning curve pretty steep, especially because the supposedely simplest things won't ever work the first time.

    After a bit of a struggle my zend back-end works fine locally. Then I want to upload it to the REAL web server because the client asks for it this week.
    So I do it and bam! New errors, open_dir restriction. I replaced the following line in index.php:

    set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../library'),
    get_include_path(),
    )));

    with simply:

    set_include_path(realpath(APPLICATION_PATH . '/../library'));

    it works!

    At least I got rid of the open_dir restriction warnings.

    But now when I try to use my back end, the first call to an action in any controller brings me a 404 file not found page!!

    Why is that??

    Every forum I find seems to speak of local configurations, where we should edit httpd conf to allow override all etc..
    But is there any real case of people using Zend for a public website?

    Any help would be greatly appreciated!

    Thanks again

    David

  15. Good tutorial. Better than the guide on the Zend site. Only noticed one minor error on page 8. "Count not find row $id" should probably be "Could not find row $id".

  16. Fatal error: Class 'Application_Model_DbTable_Albums' not found in C:Program FilesZendApache2htdocsmyapplicationcontrollersIndexController.php on line 16

    This is the error, though i have the 'Application_Model_DbTable_Albums' class written in applicationmodelsDbTableAlbums.php and using same in IndexController.php

  17. Thanks for this great tutorial, it was really usefull, I can now create a basic app with Zend Framework.

    Is there some slightly more advanced tutorial that you could advise me?

  18. Can somebody please tell me how to implement modules in Zend 1.10 ?

    I need a detailed tutorial because I have tried many on the web buty seem to be outdated.

  19. HiRob,

    I'd reccomend you to tell something about setting up a virtual host in this tutorial. I've got the example application up and running quite easy but when I'd like to add more controllers and functionallity I ran into a lot of troubles and it was a heavy search to get things solved. After I've found the information about setting up a virtual host thing got easy.

    But thanks, your tutorial was very helpfull to me!

    Cheers!

  20. Crispijn,

    Why? A virtual host is not required for ZF. I know this as I don't use them for local development :)

    Regards,

    Rob…

  21. Hi Rob,

    I ran into trouble when I added custom controllers to my application. When I had the virtual host up and running these problems were solved… Don't know why, I'm not a ZF guru, but it was.

    Could you tell me why I ran into trouble? The troubles where that all the request I've made at http://localhost/~myname/controllername/actionname I got a 404 error but your tutorial app was up and running so I guess that the overwrite setting was just as you suggested.

    Regards,

    Crispijn

  22. Hi,
    beautiful guide, but I've this error:
    Fatal error: Class 'Application_Model_DbTable_Albums' not found. But the class name is correct (Application_Model_DbTable_Albums). What's the problem? I've used the downloadable example..

    I've a lot of problem with a modules.. with a framework 1.10 the project's structure is significantly changed..

    Thank you!

  23. Great! Does anyone know how to extend this tutorial with active record validation?

    I am trying to inplemend Zend_Validate_Db_NoRecordExists so that it won't be possible to insert a new record while a record with an identical name field already exists. This works fine in case of inserts, but When the form is used to edit a record it will find itself and fail validation.

    I know I need to set an exception for th active record. The problem is that I simply don't know how to pass a variable (id) from the controller into the form.

    It should be pretty basic OOP I guess but I tried everything I could think off for more than a few nights now. I just don't see it. The manual describes this validator but somehow I can't manage to set it up. All I want is to pass a id from the controller to the form and use it.

    My form currently uses the init() method. I also tried overriding the constructor __construct($id) as well but that's no good practice as far as I am aware and it did broke the 'save' method. The init() function is for convenience according to the documentation. But I have no idea what they mean. Then there's is this configuration object which can be passed to the constructor. And there is a setAttrib method. I am completely lost.

    Any suggestions on using a constructor in stead of init() functions as in this tutorial? Could I use setAttrib for this purpose? Or implementing getter setter methods? Any help would be greatly appreciated!

  24. SELECT * FROM emp WHERE ename='smith' AND id=520

    please tell me how to implement this qury in zend frame work

  25. Thank you for the tutorial.
    When I'm trying to delete a record I get following
    Fatal error: Class 'Model_DbTable_Albums' not found in applicationcontrollersIndexController.php on line 91

    (File from source downloaded)

    This line should read:
    $albums = new Application_Model_DbTable_Albums();

    Regards.

  26. Hi Rob,

    Now there's a Bootstrap.php file I'm a little confused as to how to implement custom routing, mainly what method to override in the above class to get access to my router and enter custom routes.

    Do you have any tips on this?

    Thanks.

  27. This PDF tutorial need an update for Zend framework version of 1.10 in form class. Instead of __constructor() function we should use init() function otherwise script will consume memory space or can give memory limit exhausted error.

  28. Hi Rob,

    A lot of people seem to have problems with the database class not being found. I have the same issue. With the scripts downloaded I get the error:

    Fatal error: Class 'Application_Model_DbTable_Albums' not found in /Users/michael/Sites/zf-test/application/controllers/IndexController.php on line 16

    Can you please advice on this?

    Thanks in advance!

  29. Hi.
    I read your guide and i like it.
    I have a question: can u make an example with different views?
    I am building a website with 3 section but i have only one index in /public.
    How can i change views?

  30. For people not able to load the Application_Model_DbTable_Albums class, please check that you have the correct case for the directory and file.

    It should be:
    application/models/DbTable/Albums.php

    Note that capital D, T and A.

    Regards,

    Rob…

  31. @Rob

    I'm not sure if the issue is with the capitals. As I found out it has something to do with the version of Zend Framework.
    If I use 1.10.0 all works fine. With 1.10.2 I get the error as described above.

  32. @Rob
    The path is like you say. Besides, I did not touch downloaded files. I just unzip the file to my local server and make database configuration.

    The class in application/Bootstrap.php is empty… is this cause the error I write above?

    regards

  33. True, i'm getting the same fatal error (Fatal error: Class 'Application_Model_DbTable_Albums' not found in E:siteszfzf-tutapplicationcontrollersIndexController.php on line 16)
    I'm also using ZF 1.10.2. What's up with this? Classname is correct, i can Ctrl+click it in my eclipse, so there's no problem there…

  34. I copied the files from the zip into the application-directory and now it works. Haven't found what i've been missing so far, maybe i was too eager and should finish the whole tutorial before i check my browser?

  35. im unable to run after placing the file onto the server and facing error in path in public/index.php

  36. Hi and thanks a lot for your work.

    Sorry for my english, i'm a poor frenchie.

    Just one problem for me : isn't it possible to have datas in utf-8 in views AND in database. It was with ZF 1.9.x < 1.9.7 but now, it's just a mad thing.
    Try when Edit for example "Soldier of Love" and transform in "Soldier of Lovéàè". You obtain in MySQL : "Soldier of Lové¨"

    Regards.

  37. For some reason, specifying "localhost" in my hosts file, setting ServerName localhost and calling http://localhost resulted in a server not found.

    Once I changed my hosts file to point zf-tutorial.localhost to the proper ip and specified ServerName zf-tutorial.localhost, the server was found.

    There seems to be some inconsistency in how these settings are referred to in the tutorial. eg. http://localhost/zf-tutorial

    Also, the url(s) on page 6 eg. http://localhost/zf-tutorial/public/index/add should not have the 'public' directory specified as the server configuration already specifies it.

    1. matt,

      I'm glad you got it working. However, you should not need to set localhost in your hosts file as it should already be set. Also, you do not need to create a virtual host for localhost as http://locallhost should go to the root directory of your web server by default. For most Linux boxes, that is /var/www or /var/www/html. For a Mac, it's /Library/WebServer/Documents. On a Windows box, with IIS, it's c:inetpubwwwroot. If you aren't using the default web server for the OS (which is likely with Windows as it doesn't ship with Apache), then it depends on which Apache package you installed.

      On page 2, the tutorial says to create your ZF project "zf-tutorial" in the root directory of your web server. This is so that navigating to http://localhost/zf-tutorial/public will find the index.php file that is automatically created by the zf command line tool and avoids the need to create a VirtualHost within the Apache settings.

      Of course, if you follow the "Note" at the bottom of page 3 about live websites and create your own VirtualHost, then it points out that the url would change to http://zf-tutorial.localhost/ but that this format would not be used in the rest of the tutorial.

      Regards,

      Rob…

  38. Thanks a lot for this tutorial.

    For those that have the "Fatal error: Class 'Application_Model_DbTable_Albums' not found in IndexController.php on line 16", I fixed mine by adding that within the Bootstrap.php

    protected function _initFoo()
    {

    $loader = new Zend_Loader_Autoloader_Resource (array (
    'basePath' => APPLICATION_PATH,
    'namespace' => 'Application',
    ));

    $loader->addResourceType( 'model', 'models', 'Model');
    }

    If someone can explain me why we have to add something like that to load correctly the resources, I will ty in advance.

  39. In complement of my previous comment, you will also have to add that in the above function to have the forms working:

    $loader->addResourceType( 'form', 'forms', 'Form');

  40. @ GoldenD

    You can retrieve your data in utf-8 by adding the line below within your application.ini

    resources.db.params.charset = "utf8"

    Try again to input foreign characters in the form and then display the result, all should be ok if you have the right mysql collation, e.g. utf8_unicode_ci

  41. @ Sensi

    Thanks for Answer but not ok. I've tried with

    resources.db.params.charset = "utf8"
    and
    resources.db.params.driver_options.1002 = "SET NAMES utf8;"

    without success. It was good before ZF 1.9.7 but not since.

  42. @ GoldenD

    Hello GoldenD, being french too it was the only thing i had to add to have it working.

    What do you have in your mysqlbinmy.ini configuration file?

    I have this for both (maybe redundant) [client] and [mysqld]:

    default-character-set=utf8
    collation_server=utf8_unicode_ci
    character_set_server=utf8

  43. @ Sensi

    hmmm,

    i've no mysqlbinmy.ini.
    I've mysql5.1.36my.ini but without these keys and values.

    In phpAdmin, all is at good statement with utf everywhere.

    In fact, the tutorial works well : the only thing is when you save data, in mysql database zf-tutorial, datas are not readable chars, �à � for example.

    And my problem is that i have a project with more than 100 000 rows but datas are corrects in base, and with this zf version, they don't appear in forms. And you can test with this zf tutorial, it's the same if you write directly àéè… in mysql and try to read them with this sample. Nothing appears.

  44. @ GoldenD

    Well at least the problem should not come from this tutorial, because again I was able to save and display that same french characters (avec accents, etc) with zf-tutorial by just adding resources.db.params.charset = "utf8" in application.in, my database and its table being in utf8_unicode_ci

    Do try -if not already tried- to put the previously mentioned settings within your mysql5.1.36my.ini, restart mysql, check your database charsets with e.g. the free MySQL-Administrator windows application (Health -> System variables -> SQL -> charsets), check again your page/browser character encoding, and insert a new entry through the zf-tutorial.

    Otherwise sorry but I am a bit out of ideas. :)

  45. hey guys,

    i dont get the command line tool working as it should. i'm using win7 and xampp. when i try to create a project with the command line tool, it is always created in c:users\ but i have my projects in c:xampphtdocs. okay, i can set the path in the create command, but when i'm trying to create a controller with "zf create action add Index" it always say something like "no project found".

    i searched the web a few hours but couldn't find any solution…

    hope anybody can help me?

    thanks!

  46. @ Sensi,

    Thanks a lot Sensi.

    Like you and I said, it was not the fault of this tutorial, we are agree.

    I try again step by step and the solution was in my.ini as you said.

    With
    default-character-set=utf8
    collation_server=utf8_unicode_ci
    character_set_server=utf8
    in mysqld, it's ok.
    No need in [Client].

    A lot of thanks for your time and tests. Thanks.

  47. Hi,

    Your tutorial is too good…but my problem is, actully i want to use multiple database at the same time or we can say use multiple database simultaneously…like using cross database join query.

    please help me or suggest me what i do……

    Thanks
    Regards,
    Vicky…

  48. Great tutorial!

    The best that I did find, helped me a lot!

    They should use this one instead of the "quickstart" that they have on zendframework…

    The only mistake I did find was that the layout directory is "zf-tutorial/application/layouts/scripts/layout.phtml"
    not "zf-tutorial/application/layouts/layout.phtml"

    Thanks for great work!!!

  49. One of the first lines in this totorial is "If you are getting 404 errors when going to any page other than the home page, please make sure that you have set AllowOverride to All in your Apache configuration and have enabled the mod_rewrite extension."

    I do not know how to do this, I am a zend newbie. What I found via google didn't sound like something I could trust. I could guess around, but then if I get it wrong, I'm still back to the same thing – Having to ask anyway.

  50. Good tutorial. I was able to get the Framework started with the help of your tutorial.

    After setting up, I got this error message when I looked up index.php
    "Uncaught exception 'Zend_Controller_Dispatcher_Exception' with message 'Invalid controller specified (zf-tutorial)' in C:Program FilesApache Software FoundationApache2.2htdocszf-tutoriallibraryZendControllerDispatcherStandard.php:242 Stack trace: #0 C:Program FilesApache Software FoundationApache2.2htdocszf-tutoriallibraryZendControllerFront.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #1 C:Program FilesApache Software FoundationApache2.2htdocszf-tutorialindex.php(42): Zend_Controller_Front->dispatch() #2 {main} thrown in C:Program FilesApache Software FoundationApache2.2htdocszf-tutoriallibraryZendControllerDispatcherStandard.php on line 242
    "

    If I ran index.php from the command line php index.php – it reported that it was not able load some DB adapters.

    Seems that I did not have the php_pdo.dll and php_pdo_mysql.dll extensions in the php.ini.
    In fact, this line was not even present in the php.ini.

    Adding these lines to the php.ini resolved it.

    Next I encountered this error when I tried to bring up zf-turorial/index.php
    Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception' with message 'Invalid controller specified (zf-tutorial)' in C:Program FilesApache Software FoundationApache2.2htdocszf-tutoriallibraryZendControllerDispatcherStandard.php:242 Stack trace: #0 C:Program FilesApache Software FoundationApache2.2htdocszf-tutoriallibraryZendControllerFront.php(954):

    I had to add this line to the index.php
    $frontController->setParam( 'useDefaultControllerAlways', true );

    Only then was I able to see the first page rendered with no issues.

  51. Thanks,everything is ok, except in IndexController at line 91.Y've to change Model_DbTable_Albums() to Application_Model_DbTable_Albums().
    Nothing else !!!!

  52. good tutorial! im still a zend newbie and i need abit of some help, i keep on getting this error Warning: Invalid argument supplied for foreach() in /studhome/1/0802811/public_html/thisis50/application/views/scripts/index/index.phtml on line 42

    and this is on line 42 albums as $album) : ?>

    for some reason it wont display the infromation in my database only that error message keeps on coming up!!

    any help please
    thanks

  53. Hi,
    Zend Newbie here as well, I get application error with your tutorial. It seems there is a problem with database connection I m trying to run it on xampp on ubuntu . what shall I do ?

  54. Rob,

    I had purchased Zend Framework in Action last year and got a lot of information from it. Do you have any plans on another book covering ZF 1.10 ?

  55. Hi Rob, Congratulations for the tutorial and the book too. Is there a way to execute a join between two tables then fetch data from both tables?
    I've tried findDependentRowSet() (as shown in the book at Chapter 6) without success.
    Thank you in advance

  56. Hi
    Awesome guide and book (ZFiA).

    Today I went back to try the Zend_Tool beginning in your guide rev. 1.7.2 and I stumble on a problem during the "Testing Zend_Tool".

    zf show version gives me:
    "Zend Framework version 1.9.4" and stated in the guide it should be version 1.10.0.

    Do I have some error on my side? I have tried to reinsatll ZF several times and removed all earlier installtions of ZendFramework aswell but still get the 1.9.4 print out. I'm on Ubuntu 9.10.

    Thanks for any reply

  57. @Christoffer: if you have installed xampp or any similar environment you have a Zend folder into ..xamppphpPEARZend that prompts out that lines. Check it and eventually replace it with a newer Zend version.

  58. After creating the actions for Index and trying to go to: zf-tutorial/public/index/add I get the page not found 404 error.

    I uncommented the mod_rewrite line in httpd_conf file.

    I added this to default and documentroot settings

    Options All
    AllowOverride All
    Order allow,deny
    Allow from all

    i restarted apache and i still get 404 error

  59. I found the problem. On windows machines you cannot have .htaccess with no file name. In the http_conf file there is a line that specifies the file name for access files.

    AccessFileName ht.htaccess

    i just put ht in front and 404 error be gone.

  60. Thanks for all this tutorials. It helps a lot to get started on this tech. Your explanations are very precise and I understanded all of the tutorial. Thanks for spending effort on doing this for free.

  61. got the 'Mysql driver not found error' when trying to view the albums

    You have to include the pdo.dll's in php.ini

    extension=php_pdo.dll

    extension=php_pdo_mysql.dll

    apparently doesnt use the regular mysql driver

  62. I made it to displaying the album records and followed the directions to setup the Add Form. But when I click on Add Album It just displays 'Add New Album' title on top and blank screen below. There is no form controls. I followed the directions exactly.

  63. Thanks for this great tut.
    It´s the first one that's been helpful so far and I tried a few…

  64. erratum:

    Page 4. The htaccess file does not set the env to development. You need to add it:

    SetEnv APPLICATION_ENV development

  65. I have been struggling since an upgrade from 1.9.x to 1.10.x with my mysql data which is iso-8859-1. If you need iso-8859-1, as I do, then you now have to explicitly tell your Zend_View resource about it. In the _initView() in your Bootstrap.php:

    $view->setEncoding('iso-8859-1');

  66. If you come across "Application error" , then make sure the have Allowoverride ALL in httpd.conf. It solves the issues. Also in IndexController , for delete actions make sure to correct actions to Application_Model_DbTable_Albums

  67. Are there plans to do this tutorial with the zend layout of modules?

    /modules/default for this and
    /modules/admin or something for your Zend_Auth example

  68. I try to implement exemple from ch 04
    with a sqlite3 database
    and with zendframework 1.10
    and the part with menu not work .
    How can I make work this example
    using zendframework 1.10

  69. Hi Rob, thanks for the great tutorial. In my opinion it's better than the official quickstart one, as Zend complains less and there are more solutions.

    My problem right now is with the addAction() function in IndexController. I keep getting this error after I add an album:

    Fatal error: Uncaught exception 'Zend_Controller_Response_Exception' with message 'Cannot send headers; headers already sent in D:ZendFrameworkbinquickstartapplicationcontrollersIndexController.php, line 66' in D:ZendFrameworkbinquickstartlibraryZendControllerResponseAbstract.php:321 Stack trace: #0 D:ZendFrameworkbinquickstartlibraryZendControllerResponseAbstract.php(339): Zend_Controller_Response_Abstract->canSendHeaders(true) #1 D:ZendFrameworkbinquickstartlibraryZendControllerResponseAbstract.php(766): Zend_Controller_Response_Abstract->sendHeaders() #2 D:ZendFrameworkbinquickstartlibraryZendControllerFront.php(992): Zend_Controller_Response_Abstract->sendResponse() #3 D:ZendFrameworkbinquickstartlibraryZendApplicationBootstrapBootstrap.php(97): Zend_Controller_Front->dispatch() #4 D:ZendFrameworkbinquickstartlibraryZendApplication.php(366): Zend_Application_Bootstrap_Bootstrap->run() #5 D:ZendFrameworkbinquickstartpublicindex.php(26): Zend_Application->run() #6 in D:ZendFrameworkbinquickstartlibraryZendControllerResponseAbstract.php on line 321

    I'm betting this is because of $this->_helper->redirector('index') – when I remove it I'm neither redirected back nor getting the error. Also, despite the error, the Album does get added to the main database.

    How do I solve this?

  70. Also, I couldn't get $this->getRequest->isPost() to work, so I'm using $_SERVER['REQUEST_METHOD'] == 'POST' instead.

  71. Andre,

    Redirect issue is because you have some whitespace before the opening

    No idea about second one though :(

    Regards,

    Rob…

  72. your right rob, andre is some missing space before sending location header to buffer. i have error like this an a few hours ago. thanx rob..

  73. Solving problem like this
    Fatal error: Class 'Model_DbTable_Albums' not found in D:WebProgswampwwwTestProjectapplicationcontrollersIndexController.php on line 91
    when delete album

    Just replace line 91 in
    applicationcontrollersIndexController.php
    from $albums = new Model_DbTable_Albums();
    to
    $albums = new Application_Model_DbTable_Albums();

  74. I'm using ZF 1.10.4 so I repeated this tutorial as a replacement to chapters 2, 3 and 4 of the book.

    This quickstart is head and shoulders above the rest that are available online or in print!

    Off now to chapter 5 of ZFiA!

  75. hi,,rob..

    I have followed the tutorial you get 12 pages, at first I was using netbeans 6.8 .. but when I try running, no output at all .. then I tried again until 12 pages using notepad + +, there is output data to a database but not out ,,

    Can you explain why Rob?

  76. Rob,
    This tutorial have been very usefully in my learning. I followed all the steps and it is running fine.

    The problem comes when I want to categorize the project into modules. I never get it running.

    1. I tried to add Dojo features to make it more attractive but I have never get this one working. I have tried several tutorial but never worked.

    Can you recommend a tutorial like this which I can learn Dojo and using module?

    John

  77. Well, I think Zend company should hire your company to write the technical manual for their framework. Thanks guys!!!

  78. Near the top of page 5 of 18 it states:

    "The, application.ini, that is stored in the application/configs directory is loaded using the
    Zend_Config_Ini component."

    I can see how Zend/Application.php is created configured from public/index.php. But I don't see how Zend_Config_Ini.php is called. I see no reference to it from Zend_Application.php.

    What am I missing?

  79. Hi Rob,
    Thanks very much. I am a beginner, this tutorial is an eye opener to zend mvc.

    Cheers!

  80. Its really fantastic. You just made the Zend installation and the application so simple. Great

  81. On Page 5 you have a "Boostrap" which I assume is like a Bootstrap, but more like a Booze Trap

  82. Frank,

    It's loaded by Zend_Application, in the _loadConfig() method.

    Jim,

    Thanks! I've updated the master document.

    Regards,

    Rob…

  83. Hi Rob. Thanks very much for this awesome and clear tutorial. It has helped me get my CRUD functionality off the ground. I have one question:

    1. I am using this crud functionality on two controllers. The form for one controller needs a select box populated with the data from the second controller. If possible, can you show us a good way to implement this?

    Thank you kindly!

  84. Once copied ZF tutorial, even though I set everything exactly as it should be after clicking on add new record throws me error that the page does not exist. Not sure where the problem may be. Thank you in advance for answering.
    This is error : http://www.xxx.xx/public/index/add

  85. Alternative solution for those that have the "Fatal error: Class 'Application_Model_DbTable_Albums' not found in IndexController.php on line 16", I fixed mine by adding that within the Bootstrap.php Bootstrap class

    protected function _initAutoload() {
    $moduleLoader = new Zend_Application_Module_Autoloader(array(
    'namespace' => 'Application',
    'basePath' => APPLICATION_PATH));

    /** auto load */
    $autoloader = Zend_Loader_Autoloader::getInstance();
    $autoloader->setFallbackAutoloader(true);
    return $moduleLoader;
    }

    Thanks to mikemmx on http://www.zendcasts.com/forum/topic/23/class-not-found/ for this.

  86. Further to my last comment, you can simply add:

    protected function _initAutoload() {
    $moduleLoader = new Zend_Application_Module_Autoloader(array(
    'namespace' => 'Application',
    'basePath' => APPLICATION_PATH));
    return $moduleLoader;
    }

  87. Dear Rob,

    Thanks for this tutorial. (I enjoy with it, and I'm waiting for "Zend framework in action" that I've just ordered.)

    Here is my problem about the tutorial:
    1) I've done all what you said about UTF8 and french characters and it works perfectly for "éèïîôöùü" but not for "à".

    2) If the string ends with two "à"; the last "à" is not recorded.

    3) If the string ends with one "à", when I click edit, nothing is displayed !!!

    Is that a bug ???
    My PHP version is 5.3.2.

    Sorry for my "light" english, I am French.

  88. Thanks for this tutorial.

    I typed correctly, but encountered an error:

    "Notice: Undefined index: in /sites/zend4/library/Zend/Form.php on line 1052 Fatal error: Call to a member function getOrder() on a non-object in /sites/zend4/library/Zend/Form.php on line 1052 "

    Este erro ocorre quando chamo o addAction. Como resolver?

    obs: PHP Version 5.3.2-1
    ZF Version 1.10.6

    Thanks.

  89. Sorry, I typed the last phrase in portuguese. The correctly is: "This error occurs when I call the addAction. How to solve?"

  90. Pingback: Anonymous
  91. Rob,

    Thanks for this tutorial. It's way better than the one on zend.com. Not that the zend.com tutorial is all that bad, but they throw in way too many unnecessary things that makes newbies think that that is the way to use Zend. Your tutorial sticks to the bare minimum to get started.

    My one request is that you convert the PDF to a website of some sort! I've been referencing your PDF so much and it's much harder to navigate the PDF than it would be to navigate a website.

    Thanks again.

  92. To use this tutorial with Oracle Database here are the changes that
    need to be made. They were based on Rob's document version 1.7.2. I
    used Zend Server 5.0.2 (PHP 5.3) which had Zend Framework 1.10.3 and
    the Oracle OCI8 extension enabled. (I also used the built-in support
    for ZF that comes in NetBean's 6.9 PHP edition.)

    In application.ini I set the DB parameters to:

    resources.db.adapter = "Oracle"
    resources.db.params.dbname = "localhost/XE"
    resources.db.params.username = "cjones"
    resources.db.params.password = "secret"

    To aid trouble shooting I found setting displayExceptions to 1 was useful:

    resources.frontController.params.displayExceptions = 1

    The Oracle SQL to create the example table is:

    drop trigger album_trg;
    drop sequence albums_seq;
    drop table albums;

    create table albums (
    id number not null,
    artist varchar2(100) not null,
    title varchar2(100) not null,
    primary key (id)
    );

    create sequence albums_seq;

    create or replace trigger album_trg
    before insert on albums for each row
    begin
    select albums_seq.nextval into :new.id from dual;
    end;
    /

    insert into albums (artist, title) values ('Paolo Nutine', 'Sunny Side Up');
    insert into albums (artist, title) values ('Florence + The Machine', 'Lungs');
    insert into albums (artist, title) values ('Massive Attack', 'Heligoland');
    insert into albums (artist, title) values ('Andre Rieu', 'Forever Vienna');
    insert into albums (artist, title) values ('Sade', 'Soldier of Love');
    commit;

    Because Oracle identifiers get described in upper case and because of
    the way quoting occurs in Zend_Db, references to identifiers in PHP
    code need to be changed to upper case as you do each stage. Below is
    a diff of the final files. I did not set db.params.options.caseFolding
    or db.params.options.autoQuoteIdentifiers.

    Album.php
    --- Album.php	2010-07-15 16:36:53.537110261 -0700
    +++ ../orcl/Album.php	2010-07-15 16:36:16.364995146 -0700
    @@ -4,23 +4,23 @@
     {
         public function init()
         {
    -        $this->setName('album');
    -        $id = new Zend_Form_Element_Hidden('id');
    +        $this->setName('ALBUM');
    +        $id = new Zend_Form_Element_Hidden('ID');
             $id->addFilter('Int');
    -        $artist = new Zend_Form_Element_Text('artist');
    +        $artist = new Zend_Form_Element_Text('ARTIST');
             $artist->setLabel('Artist')
                 ->setRequired(true)
                 ->addFilter('StripTags')
                 ->addFilter('StringTrim')
                 ->addValidator('NotEmpty');
    -        $title = new Zend_Form_Element_Text('title');
    +        $title = new Zend_Form_Element_Text('TITLE');
             $title->setLabel('Title')
                 ->setRequired(true)
                 ->addFilter('StripTags')
                 ->addFilter('StringTrim')
                 ->addValidator('NotEmpty');
             $submit = new Zend_Form_Element_Submit('submit');
    -        $submit->setAttrib('id', 'submitbutton');
    +        $submit->setAttrib('ID', 'submitbutton');
             $this->addElements(array($id, $artist, $title, $submit));
         }
     }
    Albums.php
    --- Albums.php	2010-07-15 16:36:56.801733183 -0700
    +++ ../orcl/Albums.php	2010-07-15 16:37:51.013015527 -0700
    @@ -2,12 +2,12 @@
     
     class Application_Model_DbTable_Albums extends Zend_Db_Table_Abstract
     {
    -    protected $_name = 'albums';
    +    protected $_name = 'ALBUMS';
     
         public function getAlbum($id)
         {
             $id = (int)$id;
    -        $row = $this->fetchRow('id = ' . $id);
    +        $row = $this->fetchRow('ID = ' . $id);
             if (!$row) {
                 throw new Exception("Could not find row $id");
             }
    @@ -17,8 +17,8 @@
         public function addAlbum($artist, $title)
         {
             $data = array(
    -            'artist' => $artist,
    -            'title' => $title,
    +            'ARTIST' => $artist,
    +            'TITLE' => $title,
             );
             $this->insert($data);
         }
    @@ -26,14 +26,14 @@
         public function updateAlbum($id, $artist, $title)
         {
             $data = array(
    -            'artist' => $artist,
    -            'title' => $title,
    +            'ARTIST' => $artist,
    +            'TITLE' => $title,
             );
    -        $this->update($data, 'id = ' . (int)$id);
    +        $this->update($data, 'ID = ' . (int) $id);
         }
     
         public function deleteAlbum($id)
         {
    -        $this->delete('id =' . (int)$id);
    +        $this->delete('ID =' . (int)$id);
         }
     }
    IndexController.php
    --- IndexController.php	2010-07-15 16:37:00.281133620 -0700
    +++ ../orcl/IndexController.php	2010-07-15 16:38:27.594053181 -0700
    @@ -26,8 +26,8 @@
             if ($this->getRequest()->isPost()) {
                 $formData = $this->getRequest()->getPost();
                 if ($form->isValid($formData)) {
    -                $artist = $form->getValue('artist');
    -                $title = $form->getValue('title');
    +                $artist = $form->getValue('ARTIST');
    +                $title = $form->getValue('TITLE');
                     $albums = new Application_Model_DbTable_Albums();
                     $albums->addAlbum($artist, $title);
                     $this->_helper->redirector('index');
    @@ -47,9 +47,9 @@
             if ($this->getRequest()->isPost()) {
                 $formData = $this->getRequest()->getPost();
                 if ($form->isValid($formData)) {
    -                $id = (int)$form->getValue('id');
    -                $artist = $form->getValue('artist');
    -                $title = $form->getValue('title');
    +                $id = (int) $form->getValue('ID');
    +                $artist = $form->getValue('ARTIST');
    +                $title = $form->getValue('TITLE');
                     $albums = new Application_Model_DbTable_Albums();
                     $albums->updateAlbum($id, $artist, $title);
                     $this->_helper->redirector('index');
    @@ -57,7 +57,7 @@
                     $form->populate($formData);
                 }
             } else {
    -            $id = $this->_getParam('id', 0);
    +            $id = $this->_getParam('ID', 0);
                 if ($id > 0) {
                     $albums = new Application_Model_DbTable_Albums();
                     $form->populate($albums->getAlbum($id));
    @@ -72,13 +72,13 @@
             if ($this->getRequest()->isPost()) {
                 $del = $this->getRequest()->getPost('del');
                 if ($del == 'Yes') {
    -                $id = $this->getRequest()->getPost('id');
    +                $id = $this->getRequest()->getPost('ID');
                     $albums = new Application_Model_DbTable_Albums();
                     $albums->deleteAlbum($id);
                 }
                 $this->_helper->redirector('index');
             } else {
    -            $id = $this->_getParam('id', 0);
    +            $id = $this->_getParam('ID', 0);
                 $albums = new Application_Model_DbTable_Albums();
                 $this->view->album = $albums->getAlbum($id);
             }
    delete.phtml
    --- delete.phtml	2010-07-15 16:11:13.981296550 -0700
    +++ ../orcl/delete.phtml	2010-07-15 16:06:05.009061440 -0700
    @@ -1,10 +1,10 @@
     Are you sure that you want to delete
    -  'escape($this->album['title']); ?>' by
    -  'escape($this->album['artist']); ?>'?
    +  'escape($this->album['TITLE']); ?>' by
    +  'escape($this->album['ARTIST']); ?>'?
     
     <form action="url(array('action'=>'delete')); ?>" method="post">
     
    -  <input type="hidden" name="id" value="album['id']; ?>" />
    +  <input type="hidden" name="ID" value="album['ID']; ?>" />
       
       
     
    index.phtml
    --- index.phtml	2010-07-15 16:39:00.320998284 -0700
    +++ ../orcl/index.phtml	2010-07-15 16:38:43.321084453 -0700
    @@ -1,5 +1,5 @@
     <a href="url(array('controller'=>'index',
    -          'action'=>'add'));?>">Add new album
    +	  'action'=>'add'));?>">Add new album
          
          
          Title
    @@ -8,13 +8,13 @@
          
     albums as $album) : ?>
          
    -     escape($album->title);?>
    -     escape($album->artist);?>
    +     escape($album->TITLE);?>
    +     escape($album->ARTIST);?>
          
          <a href="url(array('controller'=>'index',
    -              'action'=>'edit', 'id'=>$album->id));?>">Edit
    +	      'action'=>'edit', 'ID'=>$album->ID));?>">Edit
          <a href="url(array('controller'=>'index',
    -              'action'=>'delete', 'id'=>$album->id));?>">Delete
    +	      'action'=>'delete', 'ID'=>$album->ID));?>">Delete
          
    
  93. hi,
    i try this tutorial to learn zend. But i've a problem in the models, when i delete the function in my form and zdtable model,i can display the albums but when i write all the functions in these models, the home page is empty, it's display nothing.

    So please help me ;)
    Thx

  94. I have problem with special chars.
    I want use populate() method, but this no have success when data from database return special chars. Example:
    'cloud', 'céu', 'table', 'mesa'

    in above list only input form for 'céu' is empty.
    Help me please.

    Thanks

  95. for the "Fatal error: Class 'Application_Model_DbTable_Albums' not found" error. I found that when I downloaded the files from this site the Albums.php file was in a subdir named 'DbTable' and not directly inside the 'models' dir.

    Once I created the 'DbTable' dir and put the Albums.php inside that it all worked. I see I missed that in the pdf tutorial, maybe you have too ? hth :)

  96. Thank you for the tutorial which I found really helpful.

    I am having a small bit of trouble with the last bit. The application doesn't seem to be building an incorrect sql statement to fetchrows.

    The SQL it builds to get a row from this url is
    http://quickstart.local/index/delete/id/6

    string(49) "SELECT `albums`.* FROM `albums` WHERE (6) LIMIT 1"

    the where clause should be id=6, but it's just 6 and it always returns the first record in the resultset.

    I know its difficult to debug, I just thought maybe you might have an idea.

    Thanks

  97. Hi Rob

    Thanks for the quick reply. It must be just a small typo in my code or something like that. I replaced my files with the files from the tutorial and it all works fine now, so that will be enough to get me going.

    Thanks for the tutorial

    Tom

  98. Hi Rob,

    Excellent tutorial, thank you very much. I have had to comment out one line though while going through..

    $form = new Application_Form_Album();
    //$form->submit->setLabel("Add"); <—–

    in addAction method of IndexController.

    Even though Eclipse does say I can use "setLabel" I still get a fatal error:

    Fatal error: Call to a member function setLabel() on a non-object in C:workzftestapplicationcontrollersIndexController.php on line 29

    I just commented it out for now to come back to later anyway.

    Best tutorial yet. Gonna get yer book :D

  99. @betogroo

    Make sure in application/forms/Album.php that you haven't put:

    $this->addElement(array($id, $artist, $title, $submit));

    it needs to be addElements <- note the S

  100. I have been unsuccessful in making zend framework 1.10 talking to db2 express-c edition ver 9.7.
    I also used zend studio for development. Zend studio gave me a few dlls to put in php.ini, which I did.
    When i tried to run the tutorial application from akarabat.com it says The IBM driver is not currently installed for 'pdo_ibm'
    For 'db2' adapter it says The IBM DB2 extension is required for this adapter but the extension is not loaded .

    When i checked the PHP error logs it says the following/

    PHP Startup: Unable to load dynamic library 'D:ZendZendServerlibphpextphp_ibm_db2.dll' – The specified module could not be found.
    in Unknown on line 0

    When i tried to change the dll file with the one that i got with zend studio it give sthe error message

    [27-Jul-2010 11:23:30] PHP Warning: PHP Startup: Unable to load dynamic library 'D:ZendZendServerlibphpextphp_pdo_ibm_5.2.2.dll' – The specified module could not be found.
    in Unknown on line 0
    [27-Jul-2010 11:23:30] PHP Warning: PHP Startup: Unable to load dynamic library 'D:ZendZendServerlibphpextphp_ibm_db2_5.2.2.dll' – The specified module could not be found.

    In a few forums i found that i have to have the db2 client installed if i am connecting to a db2 installed in a different machine. So i installed
    the runtime client with the control center, and I am able to query my tables using the same. But Zend is still giving the same error messages .

    I also had included the path 'D:ZendZendServerlibphpext' in the system variables. But still Zend is gives the same error messages.

    Is it possible to make Zend FWK 1.10 talkt o db2express-c9.7 ?

  101. after installing zend server in the same machine as the db machine everything works. However the db runtime client that comes with zend server doesnt seem to connect to db2 express-c.

  102. when connecting to thedatabase, would there be any differences if I was trying to map to a database view instead of a table? thanks!

    btw, excellent tutorial Rob! Thanks!

  103. First off thanks Rob for a great tutorial! For everyone getting the Application_Model_DbTable_Albums error, the issue is Rob forgot to mention in the pdf that he modified the default namespace! To fix either add appnamespace = "Application" to your application.ini or change the name of the class to Default_Model_DbTable_Albums in both the Albums.php file and in the IndexController.php file.

    1. James,

      With ZF 1.10.x, the zf command line tool sets the namespace to "Application" in the ini file though. What I can't work out is why this isn't happening for some people!

      Rob…

  104. My mistake… did not notice the version you where using. The issue might be the error is caused by users running xampp, there is a zf.bat / zf.php in their xampp/php folder that is likely over-riding the up-to-date zf.bat / zf.php file in their C:Program FilesZendFrameworkClibin folder.

  105. i have found that i did not configure my httpd.conf properly. it was pointing elsewhere where i had the same project. did not need any virtualhost. hope it helps another dizzy :-)

  106. help me!
    I don't know error!

    class Application_Model_DbTable_Users extends Zend_Db_Table_Abstract {

    protected $_name='Users';
    public function addAlbum($artist, $title)
    {
    $data = array(
    'artist' => $artist,
    'title' => $title,
    );
    $this->insert($data);
    }
    }

    when i adduser error masages
    Catchable fatal error: Object of class Application_Model_DbTable_Users could not be converted to string in F:xampphtdocszfManagerlibraryZendDbStatementPdo.php on line 228

  107. sorry
    class Application_Model_DbTable_Users extends Zend_Db_Table_Abstract {

    protected $_name='Users';
    public function saveUser($user,$pass,$fname,$infor,$cityid,$roleid)
    {
    //$db = $this->getDefaultAdapter();
    $data=array(
    'UserName'=>$user,
    'Password'=>$pass,
    'FullName'=>$fname,
    'Address'=>$infor,
    'Cityid'=>$cityid,
    'RoleId'=>$roleid,
    'Information'=>$infor,
    );
    $this->insert($data);
    }

  108. Thanks a lot for this tutorial, I manage to make everything except the style:
    in layout.phtm i have:
    headLink()->prependStylesheet($this->baseUrl().'/css/site.css'); ?> in section
    in apache error log i have:
    127.0.0.1 – – [*/*/*] "GET /zf-tutorial/public/css/site.css HTTP/1.1" 404 1602

    what I need to do to get the css file to work ??

  109. thanks for this wonderful tutorial, I had problems with configuring my httpdconf in the start but your tutorial helped and later I found that xampp itself comes with a ZF installation (I never understood why) but yes I was able to quickly go off the ground because of this tutorial. Thanks a lot again

  110. Thank you so much for this tutorial. I have one question though which I couldnt find solution for: If I want to have a common directory within the application in a modular structure how can I auto load this resource, for example in the application folder I have a folder called project and in this project I have common classes/models that is specific to the project I am working, how can I get to autoload this class?

    Thanks

  111. Hallo Rob .thx for ure marvellous tutorial…its the first too become run on my machine..its like a milestone to build enterprise solutions with ZF….
    thanx n best regards from germany…

  112. Great tutorial. But I hope you could help me on my concern. I am having problem with using the $this->dispatch(‘/path/to/action’) method. I am not redirected to the post-login page. I know I am passing proper credentials in and everything. What could have I done wrong?

  113. Hello,

    I have the folowing error:

    Serverfehler!
    Die Anfrage kann nicht beantwortet werden, da im Server ein interner Fehler aufgetreten ist. Der Server ist entweder überlastet oder ein Fehler in einem CGI-Skript ist aufgetreten.

    Sofern Sie dies für eine Fehlfunktion des Servers halten, informieren Sie bitte den Webmaster hierüber.

    Error 500

    How can I resolve it?

    Regards,

  114. error.log:

    zf-tutorial/public/.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration

    this .htaccess file is in the source attached with the tutorial !

  115. [Quote] good tutorial! im still a zend newbie and i need abit of some help, i keep on getting this error Warning: Invalid argument supplied for foreach() in /studhome/1/0802811/public_html/thisis50/application/views/scripts/index/index.phtml on line 42

    and this is on line 42 albums as $album) : ?>

    for some reason it wont display the infromation in my database only that error message keeps on coming up!!

    any help please
    thanks

    [/Quote]

    Marcus i had a similar issue. Turned out that under my IndexAction in the IndexController.php file i had written:
    $albums = new Application_Model_DBTable_Albums();
    instead of
    $albums = new Application_Model_DbTable_Albums();

    That small change did the trick for me.
    Hope that helps!

  116. Rob
    Thanks for great tutorial, I started with your book but ran into a few problems. This tutorial sorts it out.
    To others I would sugest doing this tutoral first and then the book.
    Rob is an excellent tutor

  117. I would like to test the framework on my Mac 10.5.8 but you say page 2 of the pdf "getting started with zend framework" :
    Copy to /usr/local/ZendFrameworkCli by opening Terminal and typing:
    sudo cp -r ~/Downloads/ZendFramework-1.10.6-minimal /usr/local/

    The problem : there is no /local folder in the usr!
    Thank for your help.

  118. I have not OS 10.6 then I am trying on vista. On the terminal, I get the error "can not find php.exe" when I enter zf show version

  119. to solve "not able to load the Application_Model_DbTable_Albums class",
    i have changed class name as:
    class Application_Model_DbTable_Albums extends Zend_Db_Table_Abstract
    {
    ….

    in Albums.php.
    Is the correct approach?
    thanks for your advice…

  120. Thanks for publishing the excellent tutorial. I have been evaluating a number of frameworks, including rails and django, and zend seems to be a contender (it probably helped to be a php script kiddie, since I am relatively unfamiliar with both ruby and python).

    A couple of things in the tutorial had me a bit stumped: one is you (apparently) accidentally moved your reference to "layout.phtl" from the "layouts/scripts" directory to just "layouts" — it only worked for me in the subdirectory (didn't break the app, just didn't make it pretty).

    The other thing appears to also have had several people a bit flumoxed: the specification of the database host in "application ini", for which you gave the example: "resources.db.params.host = localhost".

    Initial tests in the browser spat back a baffling array of error messages, but a google search gave me a clue, and changing it to: "resources.db.params.host = 127.0.0.1" worked for me (MySQL5x & Apache2 installed through macports of OS X 10.4).

    Thanks, and I'm giving serious thought to your book…

  121. hi rob. i like very much your tutorial. and zf in action is the best book to learn zend framework but your book was published in 2008 and you still not have updated book for zf 1.10 in your site you are guiding, how to develop with new version but if you release a new book then it will be very benifitial to all, and 1.10 seems stable version of zf since long time so it will be a good idea to release a book on that.

    thanks.

  122. Hi everyone !

    I had this error too :
    Fatal error: Class 'Application_Model_DbTable_Albums' not found in /home/alexandre/workspace/zf-tutorial/application/controllers/IndexController.php on line 13

    After some time spent on forum (couldn't find any useful tip..), it came to me that (wait for it..!) I wasn't using the right version of Zend library… silly me !

    This tutorial is delivered with 1.10 and tested with 1.10.1 !
    However, I was using 1.8.4PL1 !

    So make a little wget (download) at:
    http://framework.zend.com/releases/ZendFramework-1.10.1/ZendFramework-1.10.1.tar.gz
    and, problem solved.

    Greetings from France !

  123. I´m getting the next error in the page 12-13 of the tutorial:

    Application error
    Exception information:
    Message: Specified column "title" is not in the row

    It breaks even with the source code instead. I haven´t been able to solve the problem, unfortunately.

  124. Hello Rob,
    I am trying learn ZF with Zend framework in Action. I have began build "Places to take kids!" but this error occurs :
    "Fatal error: Call to a member function getDefaultModule() on a non-object in C:xampphtdocsPlaceslibraryZendApplicationBootstrapBootstrap.php on line 89" and I stuck there. i use zf ver 1.10.8. I am waiting your advice
    Alper

  125. for Fatal error: Class 'Application_Model_DbTable_Albums' not found

    Please check your zf version at Zend/Version.php, it should be latest i.e. 1.10, if you are using old framework 1.9.* it would probably throw error.

  126. Rob,

    Learning a lot from this so thanks for that. However, when trying to test adding or editing I am getting – Fatal error: Call to undefined method Application_Model_DbTable_Albums::addAlbum() in C:Program FilesZendApache2htdocszf-tutorialapplicationcontrollersIndexController.php on line 29

  127. I'm using your tutorial in conjunction with Zend Framework version 1.10.8. I ran into trouble right after the series of three commands that begins with the command "zf create action add Index". The commands seemed to function correctly – I received confirmation messages concerning the creation and updating of files. However, the table that follows indicates that I should see a "placeholder" page when I proceed to any of the URLs listed. If I point my browser to the first of the URLs listed, I receive a message that says "Invalid controller specified (public)" followed by a stack trace and a listing of request parameters. I get similar results when I attempt to go to any of the others. I've double-checked my Apache configuration and it seems OK.

    Stack Trace:
    #0 /usr/share/php5/ZendFramework-1.10.8/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
    #1 /usr/share/php5/ZendFramework-1.10.8/library/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch()
    #2 /usr/share/php5/ZendFramework-1.10.8/library/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
    #3 /srv/www/htdocs/zf-tutorial/public/index.php(26): Zend_Application->run()
    #4 {main}

    Request Parameters:
    array (
    'controller' => 'public',
    'action' => 'index',
    'module' => 'default',
    )

    Can you point me towards a solution?

  128. Hi John,

    I've had the same error as you. I ran meld in unix or you can use beyond compare in windows to compare against the tutorial source code. Everything should be identical expcept for applications/config/application.ini file:
    resources.db and timezone settings.

    et voila

  129. Typo? :

    The first change we need to make is to add [[is]] our timezone information for PHPʼs date and time functionality.

  130. Well, about the book, it was great, but as it was written for old version of zend, are you planning for new/updated edition of it in near future, if not, will you please recommend some other latest book/tutorial that covers zend in detail.

  131. Warning: Invalid argument supplied for foreach() in C:Program FilesZendApache2htdocstestzendapplicationviewsscriptsindexindex.phtml on line 13

    am getting this error in my page, where as my indexAction in IndexController be this one able to fetch data but not getting it into view

    $albums=new Application_Model_DbTable_Albums();
    $this->views->albums=$albums->fetchAll();

  132. please change this line
    $this->views->albums=$albums->fetchAll();
    replace views with view so that the line be

    $this->view->albums=$albums->fetchAll();

  133. hour 6 of the zend 30 minute quickstart and this…

    Got up to here:

    zf create action add Index
    zf create action edit Index
    zf create action delete Index

    And now stuck with the following error, mod rewrite is enabled…

    Anyone get past this??

    Message: Invalid controller specified (add)
    Stack trace:

    #0 C:Program Files (x86)ZendZendServershareZendFrameworklibraryZendControllerFront.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
    #1 C:Program Files (x86)ZendZendServershareZendFrameworklibraryZendApplicationBootstrapBootstrap.php(97): Zend_Controller_Front->dispatch()
    #2 C:Program Files (x86)ZendZendServershareZendFrameworklibraryZendApplication.php(366): Zend_Application_Bootstrap_Bootstrap->run()
    #3 C:Program Files (x86)ZendApache2htdocstestpublicindex.php(26): Zend_Application->run()
    #4 {main}

    Request Parameters:

    array (
    'controller' => 'add',
    'action' => 'index',
    'module' => 'default',
    )

  134. Thanks for all this tutorials.
    I have a problem that $this->getRequest->isPost() is always false, and $_SERVER['REQUEST_METHOD'] != 'POST', and $this->_request->isPost() is also false. So, Add, Edit , Delete do not work. I don't know how to do?

  135. Hello.

    When I execute "zf create action add Index", I get this error:
    Controller Index was not found.
    It's the default file structure, created by "zf create project".

    Any ideas?
    Thanks.

  136. Nice tutorial! The hangup with the "Fatal error: Class 'Application_Model_DbTable_Albums' not found" fixed itself when I replaced the application.ini file.

  137. Firstly thanks for everything Rob, helped me out a lot. The sample application download I think has an error.

    I was getting the following PHP Notice:
    Notice: Trying to get property of non-object in C:wampwwwzf-tutorialapplicationviewsscriptsindexedit.phtml on line 3

    Fix:
    $this->headTitle($this->view->title);
    To:
    $this->headTitle($this->title);

    Thanks again Ben

    p.s Merry xmas and Happy new year

  138. Thanks Rob, it worked for me very well. I have bought "Zend Framework in Action" few days ago, and seems very good. Thanks!

  139. This example is with only inserting, deleting and updating

    title1 artist1 Edit Delete
    title2 artist2 Edit Delete
    title3 artist3 Edit Delete

    How to insert a view possibility that it looks like?:
    title1 artist1 Edit View Delete
    title2 artist2 Edit View Delete
    title3 artist3 Edit View Delete


    All the best

  140. to Ivo:

    1. Create a new Action (viewAction) which select the good record

    public function viewAction {
    $id = $this->_getParam('id',0);
    if ($id > 0) {
    $albums = new Application_Model_DbTable_Albums();
    $this->view->album = $albums->getAlbum($id));
    }
    }

    2. Create a new View (view.phtml)

    escape($this->album->title); ?>

  141. oops, html tags have been dropped

    2. part again: Create a new view (view.phtml)


    <tr>
    </td>
    <?php echo $this->escape($this->album->title) ?>
    <td>

    </tr>

  142. A big thank you for this introduction to ZF tutorial.
    (I've studied it in it's french translation at http://s-jdm.developpez.com/tutoriels/php/traductions/debuter-avec-zend-framework-1-10/ )

    My questions extends a little bit the scope of this tutorial. Lets say that we extend the data model with an 1-n relation, according to the following model:

    * album (PK id, artist, title, FK idStyle)
    * styles (PK idStyle, styleName)

    I have already passed thru the tutorial and created a second controller to manage styles.

    1. View the style name in the album's list.
    What is the best practice (and how to complete it)?

    * Create a view in the database making the join between the two tables, create a model in the application corresponding to this view, and use it only for the display of the list (that's what I do for the moment);
    * In the controller's method indexAction, build a SQL query that is the join;
    * In the controller, load the two tables (2 fetchAll), and in the view, get styleName based on idStyle in the display loop.

    2. Show names of artists in the style's list.
    The goal is to have at the sight of a multivalued field and as a result of having something like this:

    Style / Artist (s) / Actions
    Classical / André Rieu, Pavaroti / Edit Delete
    Rock'n Roll / Johnny Halliday, Elvis Presley, Chuck Berry / Edit Delete
    Slow / Elvis Presly / Edite Delete
    Techno / (empty) / Edit Delete

    I confess that I did not think yet too much, and your opinion would be welcome.
    My first idea is at the controller to load the styles table line by line and perform a nested query to retrieve the list of artists that match that style. If this idea is correct, what are the methods I should use to construct the corresponding object model?

    In advance thank you for your help.

  143. dblbass,

    I'd write a method in the Albums db table class that joined to the styles and returned the appropriate result. (You'd need to use setIntegrityCheck() to do the join)

    Regards,

    Rob…

  144. Mac OS 10.4.11
    PHP 5.2.4
    Trying to go through the "Getting Started with Zend Framework" tutorial using ZF v 1.10.8.

    zf.sh and zf.php are located in /usr/local/ZendFrameworkCli/bin.

    When I execute "zf show version" I get Parse error parse error expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or in /usr/local/ZendFrameworkCli/bin/zf.php on line 38, which is where the first protected variable is declared.

    How do I fix it?

  145. PeterHF,

    Your command line PHP is version 4.x. Type php -v on the command line.

    To fix, change your PATH environment variable so that your PHP 5.2.4 cli binary is first.

    Regards,

    Rob…

  146. I am having trouble using wamp (specifically phpMyAdmin) to write SQL statements for my database. This is because once I add "resources.db.adapter = PDO_MYSQL
    resources.db.params.host = 127.0.0.1
    resources.db.params.username = sarah
    resources.db.params.password = chips88
    resources.db.params.dbname = zf-tutorial" to application.ini, the database does not show up in phpMyAdmin. I am not sure how to tell phpMyAdmin to find the database, but the tutorial says the database connection should be made automatically.

    Any thoughts?

    1. Sarah,

      You need to create the database and run the CREATE TABLE SQL command yourself in phpMyAdmin. The resources.db lines will create the connection automatically.

      Regards,

      Rob…

  147. Thanks for that working tutorial ! Even with your book's help, after hours of trial I could never make the official tuto work and was considering moving to another framework.
    Great job !

  148. I also struggled trying to implement this tutorial. However, with a tip from Rob and figuring out a bug in the tutorial or two, the tutorial delivered as advertised.

    Vincent, contact me at peter.fogg@sbcglobal.net. I'll be happy to share my experience with ZF and maybe they will help you.

    BTW, I am coming to the belief that ZF rocks. I have much experience with CakePHP. Cake and ZF are quite different animals but both occupy important places in the scheme of things.

    1. Robert,

      Which webserver are you using? If IIS, then you need to use the URL Rewrite Module. If apache, then you need to read the bit in red at the top of this page…

      Regards,

      Rob…

  149. I use Apache. I read the bit in red at the top of this page… befor asking…

    I solved the problem with Take Ownership in Windows 7 on folder ZEND in program files. And IT WORKS :o)

    Before that i try write everything posible in config files, without effect.

    Win 7 every change write into c:usersuserAppDataLocalVirtualStoreProgram FilesZend..

    However Rob thank you for help

    Great tutorial

  150. A naive questions:

    The functions in Albums.php are created by zend or did you write them yourselves?

    I'm referring to getAlbum, addAlbum, etc.

    Also where the does the parsing or URL occurs in Zend?

  151. Hi Rob,

    I am trying out sample code relating to Zend_Rest_Server using following files as mentioned in book at 12.4.3 Using Zend_Rest_Server Page No. 254

    C:xampphtdocsplacesapplicationcontrollersRestController.php

    C:xampphtdocsplacesapplicationmodelsServicePlaces.php

    C:xampphtdocsplaceslibraryPlacesServicePlaceInterface.php

    When I try to access following URL's

    http://places/rest/?method=getPlace&id=2

    http://places/rest/?method=getReviews&id=3

    an error is displayed stating that

    "XML Parsing Error: XML or text declaration not at start of entity"

    I wonder if any one in the community can help me in this regard.

  152. I'm getting a permission denied error, installed on VPS at /usr/local/ZendFramewordCli/

    the permission denied is:

    -bash: /usr/local/ZendFrameworkCli/bin/zf.sh: Permission denied

    HELP!

  153. Hi Rob,
    Just dropping a line to mention it was/is a great tutorial, keep the good work going!

    All the Best

    Fred

  154. I am newbie in zend i download your tutorial source code at: http://akrabat.com/zend-framework-tutorial/
    It very nice, it help me understand about zend. Now i need to add the pagnigation. I had done and it ok, but when i add new a record or edit a specified record i want to redirect user to the page he has view before edit or add new. but i can not, in the original source code in addAction or editAction after update database successfully then redirect to index, so it just show the first page. I want to redirect user to the page which he has view before edit record.
    Could you help me?

  155. Hi there,

    I've downloaded and extracted the Zend framework to c:ZEND and add the same to PATH as well.

    But the when I give command F:ProjectsPHP>zf create project test_project, it does nothing, it simply returns the command prompt without doing anything.

    I checked the zf.bat file in C:ZENDBIN and it is BLANK, it has nothing written in it.

    Please let me know what am I doing wrong !!

    TIA,
    Manish

  156. Hi Rob,

    Nice tutorial;
    I tried to get started with the zend framework, but encountered some issues.
    1) I managed to create a new project through the zf_tool and now the index.php file is located in the public folder. Hence I have to access the site through localhost/myProject/public/ instead of localhost/myProject.

    2) I even managed to get a Zend_form created in the indexController and shown in the index.phtml file. But, with the action set to user/login (I have a usercontroller with this action defined) submitting the form will send me to localhost/myProject/public/user/login instead of taking me to the controller.

    Do you have any idea how I need to fix these two issues?

  157. Hi Rob,

    Correction on the previous post;
    In the mean time, I managed to get the url redirection in order (or at least I think so). At the moment, when I go to localhost, it shows me the index.php page from the public folder.

    However, there is still the problem of the form-action. When I set my form action to user/login (or even index/login), it doesn't seem to look for the controller and matching action. It rewrites the url to localhost/user/login and I think it should be localhost/application/controller/user/login.
    It seems that he doesn't know where to look for controllers.

    Any idea?

  158. Hi,
    Wonderful example thanks for this tutorial, got everything right but while rendering view getting the following error-
    Notice: Undefined property: Application_Model_Property::$idproperty in C:projectsphpprojectsquickstartapplicationviewsscriptspropertyindex.phtml on line 4
    I am using idproperty as primary key,
    but its is not able to resolve it in the view.
    Also when i am printing in the mapper class i am able to get all the table values.
    ========= Controller class code ===
    public function indexAction()
    {
    $property = new Application_Model_PropertyMapper();
    $this->view->entries = $property->fetchAll();
    }
    =============index.phtml code ===
    entries as $entry): ?>
    escape($entry->idproperty) ?>
    escape($entry->title) ?>

    Any help in this regards will be highly appreciated, New to php and zend

  159. Hello Rob I have encountered the problem below. Could you please tell me what's wrong?

    Catchable fatal error: Object of class Application_Model_DbTable_Questions could not be converted to string in D:wampwwwzf-projectlibraryZendDbStatementPdo.php on line 228

  160. hii rob,
    its a great tutorial and it helps me alot..
    but now i'm developing a project in which i have to use frames to create partitions in a webpage..
    and i need some zend framework code or example for this…
    can u plz help me for this…??

    thanks in advance! :)

  161. Hi,
    in windows xp (and i suppose more recents versions), there are settings you have to add because .htaccess file is not loaded.

    1) change your .htaccess to ht.access (thank's andy)
    2) add "AccessFileName ht.htaccess" (without quotes) to apache server httpd.conf
    3) change "filename" to ht.htaccess in your .zfproject.xml file (in the xml go to projectProfile->projectDirectory->publicDirectory->htaccessFile)
    4) delete browser's cache
    5)reload action(ex http://http://localhost/zz-tutoriel-zf/public/index/delete/)

  162. Fatal error: Class 'Application_Model_DbTable_Albums' not found

    Change the name to Model_DbTable_Albums or add the "Application_" to the class name :) just figured this out

  163. I use Win XP SP3 and XAMPP 1.7.4
    I beginning with "Getting Started with Zend Framework" tutorial.
    When i type zf show version in Command Prompt, i get this error: "php.exe is not recognized as an internal or external command operable program or batch file"
    please help me fix this error!!

  164. ok for everyone who are still unable to solve this mystery, follow these steps:

    1) Create an index.php file one level above the "public" folder i.e outside the "public" folder.

    2) Open that index.php file and add the following line:

    3) On the same path where you have your new index.php file, create an .htaccess file and add the following in it:

    SetEnv APPLICATION_ENV development

    RewriteEngine On
    RewriteRule .* index.php

    4) The final step is to modify the baseUrl() function. To do the same, open the BaseUrl.php file from

    Library/Zend/View/Helper/BaseUrl.php

    Go to the baseUrl() function and modify the line that reads:

    return $baseUrl . $file;

    with

    return $baseUrl . '/public' . $file;

    5) You should be all set. If you still have issues setting this up, you can mailme {at} shouvik {dot} net

  165. Rob,

    Thanks for the tutorial. After attempting Keith Popes 1.9 app and looking online at the Zend site quickstart app, yours really is the most straightforward.

  166. Hello all, hello Rob,

    This tutorial is indeed a nice tutorial to follow and, I do believe it fits the propose. However, I do have one question:

    Often, we will have on our databases data that spams over multiple tables. On those cases, can we build on top of this tutorial ? If so, how?

    Thanks in advance

  167. I worked through the ZF quickstart and it worked as expected. Worked through this tutorial and everything worked fine until the end. It displays nothing. Viewing page source shows nothing. Same results from Firefox or Safari. Same results from project I created, or the completed one downloaded form the akrabat website.

    MacOS 10.6.7 Snow Leopard
    PHP 5.3.6
    phpMyAdmin version 3.3.2
    MySQL version 5.1.46
    Apache Server 2.2.17
    ZendFramework 1.11

    Any clues why the page won't render?

  168. Downloaded the code with Zend Framework 1.10.6.

    Pointing my browser to IndexController_indexAction yields a blank page (and view source).

    Pointing my browser to IndexController_addAction yields the expected page with form.

    After revising
    "$this->headTitle($this->view->title);"
    to
    "$this->headTitle($this->title);",

    pointing my browser to the IndexController_editAction yields the expected page with form.

    Pointing my browser to IndexController_deleteAction yields a blank page (and view source).

    I can connect to the database via phpMyAdmin with the username, password and database name in the application.ini file. I can browse the database. It just seems that the code will not display any records from the database.

    What's up with that?

  169. There were two problems with my setup. First, I updated from PHP5.3.2 to 5.3.6, but didn't use all of the configuration settings necessary. (Still not sure what I did wrong…) Second, I had to enclose the various values of the resources.db array with double quotes, namely:

    resources.db.adapter = "PDO_MYSQL"
    resources.db.params.host = "localhost"
    resources.db.params.username = "root"
    resources.db.params.password = "rootpassword"
    resources.db.params.dbname = "akradb"

    Now it works perfectly, just as advertised!

  170. Hi
    I manage to get everthing working except for the forms.

    When i click edit or delete link i get error "The requested URL /library/public/index/edit/id/1 was not found on this server."

    can anyone tell me how to enable form action??
    thanks

  171. Hello,

    When I navigate to http://localhost/zf-tutorial/public/ I receive this error
    Warning: Invalid argument supplied for foreach() in C:xampphtdocszf-tutorialapplicationviewsscriptsindexindex.phtml on line 17. I have checked over everything and do not see any typos but then again its just me looking at this. What could be causing this error?

  172. I am having this error by just starting local host.I am trying to create Authentication scripts Before I didnt see any error.

    Fatal error: Uncaught exception 'Zend_Db_Adapter_Exception' with message 'Configuration array must have a key for 'dbname' that names the database instance' in C:UsersPandyaDownloadsSoftwareZendFrameworklibraryZendDbAdapterAbstract.php:287 Stack trace: #0 C:UsersPandyaDownloadsSoftwareZendFrameworklibraryZendDbAdapterAbstract.php(183): Zend_Db_Adapter_Abstract->_checkRequiredOptions(Array) #1 C:UsersPandyaDownloadsSoftwareZendFrameworklibraryZendDb.php(257): Zend_Db_Adapter_Abstract->__construct(Array) #2 C:UsersPandyaDownloadsSoftwareZendFrameworklibraryZendApplicationResourceDb.php(142): Zend_Db::factory('mysqli', Array) #3 C:UsersPandyaDownloadsSoftwareZendFrameworklibraryZendApplicationResourceDb.php(154): Zend_Application_Resource_Db->getDbAdapter() #4 C:UsersPandyaDownloadsSoftwareZendFrameworklibraryZendApplicationBootstrapBootstrapAbstract.php(681): Zend_Application_Resource_Db->init() #5 C:UsersPandyaDownloadsSoftwareZendFrameworklibraryZendApplica in C:UsersPandyaDownloadsSoftwareZendFrameworklibraryZendDbAdapterAbstract.php on line 287

    ————————————–
    application.ini file code
    ————————————–

    hpSettings.display_startup_errors = 0
    phpSettings.display_errors = 0
    includePaths.library = APPLICATION_PATH "/../library"
    bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
    bootstrap.class = "Bootstrap"
    resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"

    resources.db.adapter = mysqli
    recources.db.params.host = localhost
    recources.db.params.username = root
    recources.db.params.password =
    recources.db.params.dbname = youlyst

    [staging : production]

    [testing : production]
    phpSettings.display_startup_errors = 1
    phpSettings.display_errors = 1

    [development : production]
    phpSettings.display_startup_errors = 1
    phpSettings.display_errors = 1
    resources.frontController.params.displayExceptions = 1

    ————————————–
    In These two function I created in class AuthenticationController which extends Zend_Controller_Action.
    ————————————–
    public function loginAction()
    {
    // action body
    $authAdapter = $this ->getAuthAdapter();

    $username = 'hap@hap.com';
    $password = 'pass123';

    $authAdapter ->setIdentity($username)
    ->setCredetial($Password);

    $auth = Zend_Auth::getInstance();
    $result = $auth ->authenticate($authAdapter);

    If($result -> isvalid()){
    echo "valid";
    }else{
    echo "Invalid";
    }
    }

    Private function getAuthAdapter()
    {
    $authAdapter = new Zend_Auth_Adapter_DbTable(Zend_Db_Table::getDefaultAdapter());
    $authAdapter ->setTableName('user')
    ->setIdentityColumn('u_email')
    ->setCredetialColumn('Password');
    return $authAdapter;
    }

  173. Thank you for this one. It's a good start for me being a Zend Framework Junior Programmer without or haven't worked with it before :)

  174. Fatal error: require_once() [function.require]: Failed opening required 'Zend/Application.php' (include_path='/opt/lampp/htdocs/zf-tutorial/library:.:/opt/lampp/lib/php') in /opt/lampp/htdocs/zf-tutorial/public/index.php on line 18
    Can you help?

  175. *Class 'Application_Model_DbTable_Albums' not found–this problem happen to many.here a solution:put this 3 line on application.ini file in production section.

    appnamespace = "Application"

    resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"

    resources.frontController.params.displayExceptions = 0

    the cause of this problem is we create the files manually instead of command line tool.so the above line was not created automatically in application.ini file.

  176. Hi

    I am new in zend. I am developing test site using MAMP server. I am getting error

    Exception information:

    Message: No adapter found for Application_Model_DbTable_Albums
    Stack trace:

    #0 /Applications/MAMP/htdocs/zf107/library/Zend/Db/Table/Abstract.php(739): Zend_Db_Table_Abstract->_setupDatabaseAdapter()
    #1 /Applications/MAMP/htdocs/zf107/library/Zend/Db/Table/Abstract.php(268): Zend_Db_Table_Abstract->_setup()
    #2 /Applications/MAMP/htdocs/zf-tutorial/application/controllers/IndexController.php(13): Zend_Db_Table_Abstract->__construct()
    #3 /Applications/MAMP/htdocs/zf107/library/Zend/Controller/Action.php(513): IndexController->indexAction()
    #4 /Applications/MAMP/htdocs/zf107/library/Zend/Controller/Dispatcher/Standard.php(295): Zend_Controller_Action->dispatch('indexAction')
    #5 /Applications/MAMP/htdocs/zf107/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
    #6 /Applications/MAMP/htdocs/zf107/library/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch()
    #7 /Applications/MAMP/htdocs/zf107/library/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
    #8 /Applications/MAMP/htdocs/zf-tutorial/public/index.php(26): Zend_Application->run()
    #9 {main}

    Request Parameters:

    array (
    'controller' => 'index',
    'action' => 'index',
    'module' => 'default',
    )

    This is my application.ini file

    [production]
    phpSettings.display_startup_errors = 0
    phpSettings.display_errors = 0
    includePaths.library = APPLICATION_PATH "/../library"
    bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
    bootstrap.class = "Bootstrap"
    appnamespace = "Application"
    resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
    resources.frontController.params.displayExceptions = 0

    resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
    [staging : production]
    resources.db.adapter = "PDO_MYSQL"
    resources.db.params.host = "localhost"
    resources.db.params.username = "root"
    resources.db.params.password = "root"
    resources.db.params.dbname = "zf-tutorial"
    resources.db.isDefaultTableAdapter = true
    resources.view.doctype = "XHTML1_STRICT"

    [testing : production]
    phpSettings.display_startup_errors = 1
    phpSettings.display_errors = 1

    [development : production]
    phpSettings.display_startup_errors = 1
    phpSettings.display_errors = 1
    resources.frontController.params.displayExceptions = 1

    can anyone help me?

  177. First of all thanks for your tutorial , help me a lot to get in.

    I turn arround to have a management by module this is done, but based on your tutorial I don't know how to get the module name in :
    $this->url(array('module'=> 'index', 'controller'=>'index','action'=>'add')

    I did that , but the module name don't show up.

  178. Pankaj — Does comment #34 above help?

    Also, is the Zend Framework library in your include path, or in the library directory of the application?

    Is your database server up and running?

    (Wasted an hour or so on that one myself!)

  179. hi i am a newbie and was using your tutorial for zend framework. i did it step by step but when i tried to execute the action link i.e. http://localhost/zf-tutorial/public/index/add i am getting the 404 error. i even changed the "Allowoverride All" in httpd.conf file. also my file has the mod_rewrite option uncommented. But still its giving the same error.

  180. hi,
    I am new bie in zend i used to implement a zend application with refering your example. here i cant be able to access dbtable class in another controller instead of indexcontroller. i created one controller and tried to add the same code in that controller. can u help me on this..

  181. Hi Frank,

    Thanks for help.

    the problem is on the db connection.

    the db connection code should be appear above the "[staging : production]" in my case this is appear below the "[staging : production]"

  182. Thanks Rob for publishing this. I have tried to get my head around ZF on and off for the last 12 months without much progress. Following the steps in example have been very helpful and I will now progress to your excellent book!

  183. Thanks so much rob, im .net programmer and i have been trying zend for about 2 weeks without much progress.
    With this example, now i see so much clear.

    excellent work!

    thanks from chile!

  184. Hello all

    i am beginner to zend framework. just now i have installed zend framework and it's working fine on local. but to access index.php i have to use path as follow
    http://localhost/myproject/public/index.php
    but is there any way to set path directly to
    http://localhost/myproject/index.php

    i have found solution setting path in httpd.config in appache for virtual host but i have some more project in xampp htdocs so is there any other way to set path directly pointing to index.php for every project individually

    is it possible with .htaccess file?

    thanks and regards
    kamlesh bar

  185. hey,i have heard that you gonna inroduce your new book soon (zend framework 2.0 in action ) may i know when ? and i have read a little from ur book (zf in action) but i found it difficult for beginner like me ,other book make it easier spetcially when dealing with zf tool! so just a notice ;) thanks for this great tutorial

  186. I have started this tutorial, and I am halfway now. But I was wondering, how can I seperate a admin page?

    Right now editing and adding new albums are able to be done in public, but what if i'd want this seperate behind a admin panel?

    Anyway you could point me in the right way?
    Also, would you recommend me(a total beginner with zend) buying Zend Framework in Action or Zend Framework in action 2.0?

  187. Forgive me if this is obvious, but in IndexController.php line #15:

    $this->view->albums = $albums->fetchAll();

    where was the 'albums' attribute for this view object created? or is dynamically created right here?

    Outstanding tutorial btw.

  188. Hi

    I have developed one small zend application on localhost and now I want to load it on bluehost server.
    I am getting error

    Fatal error: Class 'Model_Login' not found

    can anyone help me?

  189. Is there a tutorial ANYWHERE that shows how to do this with relational databases? This is great and all, but totally impractical to scale. I'm stuck trying to link id's from other tables for dependent data…

  190. @John — That's the million $$$ question, and the answer isn't trivial. Get ready for a lengthy, partial answer to your question.

    First, you have to set up table relations. To do this, modify the model classes Places.php, Reviews.php and Users.php as shown below. See the ZF Documentation at http://framework.zend.com/manual/en/zend.db.table.relationships.html. Make sure to follow the link to the sample database used in the examples. Then, you have to modify your view script index.phtml. Sorry, but I don't have the code necessary to use the form to add, update or delete data from related tables. But you should be able to get started with this.

    //
    // application/models/DbTable/Places.php
    //
    fetchRow('id = ' . $id);
    if (!$row) {
    throw new Exception("Could not find row $id");
    }
    return $row->toArray();
    }

    public function addPlace($name, $a1, $a2, $a3, $t, $c, $p, $cntry)
    {
    $data = array(
    'address1' => $a1,
    'address2' => $a2,
    'address3' => $a3,
    'town' => $t,
    'county' => $c,
    'post' => $p,
    'county' => $cntry,
    );

    $this->insert($data);
    }

    public function updatePlace($id, $a1, $a2, $a3, $t, $c, $p, $cntry)
    {
    $data = array(
    'address1' => $a1,
    'address2' => $a2,
    'address3' => $a3,
    'town' => $t,
    'county' => $c,
    'post' => $p,
    'county' => $cntry,
    );

    $this->update($data, 'id = '. (int)$id);
    }

    public function deleteReview($id)
    {
    $this->delete('id =' . (int)$id);
    }
    }

    //
    // application/models/DbTable/Reviews.php
    //
    array(
    'columns' => array('places_id'),
    'refTableClass' => 'Application_Model_DbTable_Places'
    ),
    'Users' => array(
    'columns' => array('user_id'),
    'refTableClass' => 'Application_Model_DbTable_Users'
    )
    );

    public function getReview($id)
    {
    $id = (int)$id;
    $row = $this->fetchRow('id = ' . $id);
    if (!$row) {
    throw new Exception("Could not find row $id");
    }
    return $row->toArray();
    }

    public function addReview($places_id, $body, $rating)
    {
    $data = array(
    'places_id' => $places_id,
    'body' => $body,
    'rating' => $rating,
    );

    $this->insert($data);
    }

    public function updateReview($id, $body, $rating)
    {
    $data = array(
    'body' => $body,
    'rating' => $rating,
    );

    $this->update($data, 'id = '. (int)$id);
    }

    public function deleteReview($id)
    {
    $this->delete('id =' . (int)$id);
    }

    }

    //
    // application/models/DbTable/Users.php
    //
    <?php

    class Application_Model_DbTable_Users extends Zend_Db_Table_Abstract
    {

    protected $_name = 'users';
    protected $_primary = 'id';

    protected $_dependentTables = array('Application_Model_DbTable_Reviews');

    }

    //
    // application/views/scripts/index/index.phtml
    //
    title = "Reviews";
    $this->headTitle($this->title);
    ?>

    <a href="url(array('controller'=>'index',
    'action'=>'add'));?>">Add review

    Place
    Review
    Rating
    By
     
     

    reviews as $review) : ?>

    escape($review->findParentRow('Application_Model_DbTable_Places')->name);?>
    escape($review->body);?>
    escape($review->rating);?>
    escape($review->findParentRow('Application_Model_DbTable_Users')->username);?>

    <a href="url(array('controller'=>'index',
    'action'=>'edit', 'id'=>$review->id));?>">Edit
    <a href="url(array('controller'=>'index',
    'action'=>'delete', 'id'=>$review->id));?>">Delete

    Helpful Links:
    AKC: Golden Retriever |
    Wiki: Golden Retriever

  191. Well i'm a noob in apache configuration and .htaccess file, i don't know where to put this .htaccess, i don't know what to edit to set AllowOverride to All in ubuntu.

    ps: mod_rewrite is enabled

  192. The .htaccess file is a hidden file, and is in the application/public folder.

    The apache configuration file depends on where apache is installed. Search for "httpd.conf."

    Make a backup copy before diddling with it just in case.

  193. This is the best tutorial i could find on Zend Framework. Been trying to switch from Codeigniter to Zend. Not too much difference. Kinda. Thanks anyways.

  194. Please I don't understand in your tutorial this part of code :
    $id = $this->_getParam('id', 0);
    if ($id > 0) {
    $albums = new Application_Model_DbTable_Albums();

    in the IndexController::editAction

    Thanks :)

  195. Hi to everybody.

    How could we adapt the example above to follow the PRG pattern?

    The question is that if not, following the example as it is, you can refresh the page and delete (for example) more than one album…

    thank you
    mawey

  196. Thank you Mr Pankaj you were so helpful , thanks for all who finds problems and write how to be solved. thank you all

  197. Who knows hot to fix problem:

    C:wampwwwzf-tutorial>zf create action edit Index
    Note: PHPUnit is required in order to generate controller test stubs.
    Creating an action named edit inside controller at C:wampwwwzf-tutorial/appli
    cation/controllers/IndexController.php
    PHP Notice: Undefined variable: testActionMethodResource in C:ZendFrameworkCli
    libraryZendToolProjectProviderAction.php on line 214
    PHP Stack trace:
    PHP 1. {main}() C:ZendFrameworkClibinzf.php:0
    PHP 2. ZF::main() C:ZendFrameworkClibinzf.php:623
    PHP 3. ZF->run() C:ZendFrameworkClibinzf.php:74
    PHP 4. ZF->_runTool() C:ZendFrameworkClibinzf.php:117
    PHP 5. Zend_Tool_Framework_Client_Abstract->dispatch() C:ZendFrameworkClibin
    zf.php:600
    PHP 6. Zend_Tool_Framework_Client_Abstract->_handleDispatch() C:ZendFramework
    ClilibraryZendToolFrameworkClientAbstract.php:241
    PHP 7. Zend_Tool_Framework_Client_Abstract->_handleDispatchExecution() C:Zend
    FrameworkClilibraryZendToolFrameworkClientAbstract.php:318
    PHP 8. call_user_func_array() C:ZendFrameworkClilibraryZendToolFramework
    ClientAbstract.php:324
    PHP 9. Zend_Tool_Project_Provider_Action->create() C:ZendFrameworkClilibrary
    ZendToolFrameworkClientAbstract.php:0

    Notice: Undefined variable: testActionMethodResource in C:ZendFrameworkClilibr
    aryZendToolProjectProviderAction.php on line 214

    Call Stack:
    0.0040 454240 1. {main}() C:ZendFrameworkClibinzf.php:0
    0.0041 454240 2. ZF::main() C:ZendFrameworkClibinzf.php:623
    0.0282 801488 3. ZF->run() C:ZendFrameworkClibinzf.php:74
    0.0282 801488 4. ZF->_runTool() C:ZendFrameworkClibinzf.php:117
    0.0348 890592 5. Zend_Tool_Framework_Client_Abstract->dispatch() C:Ze
    ndFrameworkClibinzf.php:600
    0.9934 5576104 6. Zend_Tool_Framework_Client_Abstract->_handleDispatch(
    ) C:ZendFrameworkClilibraryZendToolFrameworkClientAbstract.php:241
    0.9938 5576624 7. Zend_Tool_Framework_Client_Abstract->_handleDispatchE
    xecution() C:ZendFrameworkClilibraryZendToolFrameworkClientAbstract.php:3
    18
    0.9938 5576872 8. call_user_func_array() C:ZendFrameworkClilibraryZe
    ndToolFrameworkClientAbstract.php:324
    0.9938 5577208 9. Zend_Tool_Project_Provider_Action->create() C:ZendFr
    ameworkClilibraryZendToolFrameworkClientAbstract.php:0

  198. I've tried many tutorials, books, code samples and videos but this tutorial finally helped the penny drop. Simple but functional. Accurate and flawless. I know have a grasp of Zend Framework on which to embark on my project. Thank you. John.

  199. I tried your tutorial but i have an error with front controller(Zend_Controller_Dispatcher_Exception) and if if try setBaseUrl instead of dispatcher() no error but nothing displayed.

    thanks for any solution

  200. Hi, my index.php from public allways display the zend page, and not show the index from indexcontroller, i think i followed all the tutorial, don't know what went wrong, if you can help me i'll be very gratefull x)

  201. Actually I have read the tutorial in framework.zend.com. but I still can not catch up the quick start. But this tutorial helped me to built my 1st Zend application. Thank you very much.

  202. Rob

    Many thanks for this tutorial, I've recently moved onto thinking more about ZF. After looking at the "quick start" on ZF's website, at first I put it all away back in its box and put it in the loft. A year later, I have unpacked it again and now (thanks to you) I've started playing with this toy.

    My only problem (in November 2011) has been the Application_Model_DbTable_Albums error that others have mentioned (using ZF 1.11). After reading comments by others on this page, I included a method in the Bootstrap, which took care of the problem.

    I hope you decide to add a few more example tutorials like this in the future; perhaps going further into ZF and how to build more complex sites with it (e.g. and admin back end/front-end)…?

    Thanks again

  203. Hi, thank u Rob Allen, i m very new to zend frame work, but i have clear idea about this frame work and i know the flow of this framework. thank you once again.

    by
    kumanan.c

  204. Would the book "Zend Framework in Action" have new edition published based on Zend Framework 2.0?
    I hope the new edition publish as soon as possible.

  205. Hi, many thanks for this tutorial, but I still have a question.
    After creating the actions for Index and going to any page other than the home page I get the page not found 404 error.

    I have set AllowOverride to All in your Apache configuration and have enabled the mod_rewrite extension, like this:

    LoadModule rewrite_module modules/mod_rewrite.so

    Options FollowSymLinks
    AllowOverride All
    Order deny,allow
    Allow from all

    I am using win 7, wamp 2.2, apache 2.2.21, PHP 3.3.8 .

    What other modification do I have to do to get the tutorial completely useful?

    Thank you for you answer!
    Csaba Farkas

  206. Had a suggestion for your tutorial, something I ran into when I was first starting out with Zend. You mention that actions need to be in the format {action}Action, where {action} is completely lowercase, and you note that controllers must be of the format {Controller}Controller where the first letter must be capitalized… but you don't mention that the rest of the controller name needs to be lowercase after the first character. The first tutorial didn't mention any of this, so I'm glad you included it… but that additional detail regarding Controller naming might be useful to those of us who think in camelCase and don't understand why our Controllers won't work.

  207. Hi Rob,

    Great tutorials, much easier to understand than the actual documentation on the Zend site.

    One thing, i have everything working perfectly and have my modules setup nicely and i'm finishing this login functionality, what i need is an error to be returned if the user login credentials are wrong or don't exist; at the moment if the elements don't validate i get the usual errors, but really need an error returned if the user credentials are returned false, is it just the usual Exception that i would throw for this?

    Thanks ;-)

    Derek

  208. Hi Rob,

    I worked it out, i was initially trying to use the:

    $this->view->errors, but that didn't work because on the view it was trying to get the value from the element, which wasn't available.

    So in the controller i changed your part of the index action, which collects the post to the following:

    if ($this->_process($form->getValues())) {
    $this->_helper->redirector('index', 'index');
    }else{
    $this->view->error = 'Sorry, your credentials we not found';
    }

    Then in the view i added the following:

    error): ?>
    escape($this->error) ?>

    I'm sure there is a better way of doing this using an adapter and there are a few tutorials on that around the web but they all date back to 2007 > 2009, which are out of date and with the looming version 2.0 it might be best to work with the newer functionality.

    As you may see i'm new to this but getting there, is there no UK based classroom training for learning the framework, thats something i would certainly attend.

    Thanks

    Derek

  209. "zf create action add Index" begets.

    Bishop public # zf create action add Index
    An Error Has Occurred
    A project profile was not found.

    Zend Framework Command Line Console Tool v1.10.7
    Details for action "Create" and provider "Action"
    Action
    zf create action name controller-name[=Index] view-included[=1] module

  210. I've tried following the tutorial. But when I visit the page (/zf-tutorial/public/) i'm getting an error (500).

    I've checked my apache log, but there's no error of whatsoever.

    I'm using MAMP on a MAC. please help

  211. Thanks Rob, I have learnt zend with your pdf.It was wonderful. Helped a lot.Looking forward for more tutorials from you on RESTful Webservices using Zend.

  212. I have issue with zend router can you help me to resolve it

    Zend router works fine but when i tried to access using $this->url('controller','action');

    Still get the old url instead of updated router url

  213. Pingback: include frage
  214. Hi Rob, I bought your book ZF in Action off Amazon and have found it great.

    I was wondering with IE9 have you found any strange behaviors with Jquery not working when combined with ZF.

    I have it working in the other IEs FF and Chrome just not IE9 it doesn't matter whether I include Jquery via a headscript call and house the url in the indexcontroller or just have as a standard link inline script in my header with is house in a partial script folder in my views.

    Thing is it happens in all my sites wordpress and zend??

    Is it just me or it is it a behavior other more experinced ZF users can easily negotiate.

    Kind Regards John

  215. hi all,
    i tryed zend official site quickstart tutorial and i was stuck in the middle.so i installed zend server CE.
    now im trying this tutorial,if try to go to http://localhost/zf-tutorial/public/
    i got this error message

    An error occurred
    Page not found
    Exception information:

    Message: Invalid controller specified (zf-tutorial)
    Stack trace:

    #0 C:UsersNtwobikezf-tutoriallibraryZendControllerFront.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
    #1 C:UsersNtwobikezf-tutoriallibraryZendApplicationBootstrapBootstrap.php(97): Zend_Controller_Front->dispatch()
    #2 C:UsersNtwobikezf-tutoriallibraryZendApplication.php(366): Zend_Application_Bootstrap_Bootstrap->run()
    #3 C:UsersNtwobikezf-tutorialpublicindex.php(26): Zend_Application->run()
    #4 {main}

    Request Parameters:

    array (
    'controller' => 'zf-tutorial',
    'action' => 'public',
    'module' => 'default',
    )
    for the privious tutorial i made virtualhost in httpd.conf.but now i removed that code segment.please help me to solve this one

  216. For some reason the form object is not being created and I keep getting this error:
    Call to a member function setLabel() on a non-object

Comments are closed.