Tutorial: Getting Started with Zend Framework 1.8

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 extensively rewritten for version 1.8 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.

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

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.

If you are deploying to a "user" site (e.g. http://localhost/~rob), then change the RewriteBase line in your .htaccess file should be: RewriteBase /~rob/zf-tutorial/public/.

English version: Dowload the PDF (v1.6.2).

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.

Previous versions of this tutorial

The tutorial for Zend Framework 1.5, 1,6 and 1,7 is still available, along with the translations for it. You can also find original tutorial for Zend Framework 1.0.

Changelog

1.6.2
Code in deleteAction() now matches code in zip file! Thanks to Luis and Oleg Lobach.
1.6.1
Minor fixes. Thanks to Tomas Fejfar and Luis.
1.6.0
Completely updated and significant portions revised for Zend Framework 1.8

115 Responses to “Tutorial: Getting Started with Zend Framework 1.8”

  1. 1 Jon’s Blog » Zend Framework 1.8 Tutorial

    [...] Click here for the full details » [...]

  2. 2 Mario Bittencourt

    Hi,

    I've finished reading the tutorial. Easy to follow but still touching a lot of required and important areas of the ZF.

    Good stuff to get started!

  3. 3 Fábio T. da Costa

    Great article, I'm starting a new project and I'll use the ZF 1.8.

  4. 4 Wojciech Naruniec devBlog » Mamy przeÅ‚om? Zend Framework 1.8.0

    [...] Najlepszą drogą do zapoznania się z nowymi narzędzami może być oficjalny przewodnik Zend Framework Quick Start, a także przewodnik Roba Allena. [...]

  5. 5 Wojciech Naruniec devBlog » Zend Framework 1.8.0 has been released

    [...] You can find out more about new RAD features reading Zend Framework Quick Start and Zend Framework Tutorial by Rob Allen. [...]

  6. 6 Oleg Lobach

    Thanks for great tutorial and operational changes for ZF1.8 release.

    But in delete action something strange - why you use $form variable and where it initialized?

  7. 7 Rob...

    Oleg,

    Fixed in version 1.6.2.

    Regards,

    Rob...

  8. 8 Zend Framework 1.8 erschienen | KingCrunchs kleine Welt

    [...] Akrabat hat auch schon sein Tutorial auf 1.8 angepasst. Author: KingCrunch Categories: PHP, Zend Framework Tags: Kommentare [...]

  9. 9 Joe Devon

    Nice tutorial, but one thing I'm not clear on is how to use my own configuration variables in the application.ini and access them?

    For example, in earlier ZF versions, I could put a custom setting in app.ini:
    cms.max.feeds = 10

    Then in the bootstrap:
    $configuration = new Zend_Config_Ini(
    APPLICATION_PATH . '/config/app.ini',
    APPLICATION_ENVIRONMENT
    );
    $registry = Zend_Registry::getInstance();
    $registry->configuration = $configuration;

    The in the controller this worked:
    $this->_nMaxFeeds = INTVAL(Zend_Registry::getInstance()
    ->configuration
    ->cms
    ->max
    ->feeds);

    but now I have no idea to get the same functionality in ZF 1.8.0.

    I tried following your tutorial, the Quickstart, reading the ZF docs and reading through a good chunk of the code and am stuck.

    Thanks.

  10. 10 Rob...

    Joe,

    In a controller method, you can do this:

    
    $bootstrap $this->getInvokeArg('bootstrap');
    $configArray $bootstrap->getOptions();
    
    

    If you want it as a Zend_Config object, then add this line:

    
    $config = new Zend_Config($configArray);
    
    

    Regards,

    Rob...

  11. 11 Joe Devon

    Aaah. Thank you so much!

  12. 12 Colleen Dick

    Am I just stupid or did I miss something. I set up the tool and tried to get the scaffolding to come up. it can't seem to include Application.php, and I know that is there.

    Failed opening required 'Zend/Application.php' (include_path='/var/www/zf-tut/library:.:/usr/share/php:/usr/share/pear' in /var/www/zf-tut/public/index.php on line 18

    but look:
    /var/www/zf-tut/library/Zend$ ls -al Application.php
    -rw-rw-r-- 1 colleen colleen 9232 2009-05-03 20:31 Application.php

  13. 13 Colleen Dick

    I got it to work by deepsixing the symlink to the Zend library and actually copying it. It would be nice to know why the symlink didn't work. It has always worked in my other ZF experiments.

  14. 14 Jacek

    Hi!

    While working with previous releases of ZF, I was always setting the baseUrl via FrontController:
    $frontController->setBaseUrl('/some/path');

    How to set this path now?

    Also, I am using .htaccess file to start my app, in root directory:
    RewriteRule .* public/index.php

    But using it now (I am not using VirtualHost to set the path to public dir) makes ZF display 'Page not found' error.

    How do I solve this?

    Regards,
    Jacek

  15. 15 Djaarf

    Again it is necessary to alter all :(. Thanks for your work!

  16. 16 Jacek

    OK - I've solved it :)
    I've just added a line of code in application.ini file:
    resources.frontController.baseUrl = "/some/path"

    Regards,
    Jacek

  17. 17 Colleen Dick

    Thanks it all works. Like the new auto tools, hope they include a default layout or option therefore, now must go read the help. :)

  18. 18 Colleen Dick

    OK now I am very confused how I adapt stuff written w/ earlier Zend to 1.8 For example, I have this line

    $frontController->registerPlugin(new Custom_Controller_Plugin_MemcachedSetup(),96);

    in an old bootstrap file in the runApp method. Where do I put it now? And are we still stuck with those stupid ordering numbers? Because I think they are kludgy.

  19. 19 Joe Devon

    Why is $bootstrap = $this->getInvokeArg('bootstrap');
    only available in a controller method?

    Config data is needed all over the place.

    I'm converting my code to 1.8.0 and for example need to access the config variables in a controller action helper, but it returns "Fatal error: Call to undefined method Zend_Controller_Action_Helper_MyHelper::getInvokeArg()"

  20. 20 Zend Framework and Microsoft IIS | Juozas devBlog

    [...] task today was to make Rob Allen's Zend framework tutorial project run on Windows. Some years ago such task could have been a problem, but as you will see, [...]

  21. 21 Rob...

    Joe,

    From a controller action, can't you just use $this->getController()->getInvokeArg('bootstrap') ?

    If you really need config everywhere, then you could do this:

    
    class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
    {
        public function run()
        {
            Zend_Registry::set('config', 
                new Zend_Config($this->getOptions()));
            parent::run();
        }
    }
    
    

    The config file will now be in the registry as a Zend_Config object.

    Regards,

    Rob...

  22. 22 Joe Devon

    Thanks Rob. I've rewritten my code to circumvent it but it's very useful being able to put it all in the registry just in case.

  23. 23 Zend Framework: Akrabat’s Quick Start Tutorial | eKini: Web Developer Blog

    [...] The PDF can be downloaded here directly. And you can find some notes from his blog post here. [...]

  24. 24 Konopnickiej.Com Blog » ZostaÅ‚a wydana wersja Zend Framework 1.8.0 Ponad 200 błędów poprawionych, kilka nowych komponentów oraz narzÄ™dzi

    [...] Zend Developer Blog. Zmianie ulegÅ‚y także  Zend Framework QuickStart oraz Å›wietny tutorial Roba Allana (Akra's DevNotes). Author: PaweÅ‚ Wojciechowski Categories: Zend Framework Tags: Zend Framework Komentarze [...]

  25. 25 Colleen Dick

    I understand that stuff written with the old bootstrap way will work just fine but I want to convert a small project to the 1.8 way so I can LEARN what the correspondences are. All I've seen so far is small examples of the new way without much bootstrapping. Could we have a concise point by point comparison for example: how and WHERE do you register plugins & helpers first the old way then the new way. What do these _init* things correspond to if anything in the old way. I need EXACTLY everything spelled out. just giving me code snippets won't work because I will have no idea where it goes. I think I understand they can now be resources in some way and you put them in the config yes? ??? But I am just not putting together all the pieces. I have asked questions and people give me hand wavy answers as if I already should KNOW. But I don't KNOW and I want to learn but I can't learn if I just hear glib instructions like "oh just put it in the config." What exactly is "IT" and what does the config look like and then once I do that how and where do I use it! How I learn is pretty much strictly by example. I do not understand verbal explanations very well. Is there a new ZFiA with all this in it and can I download it?

  26. 26 Joe Devon

    Rob,

    "If you really need config everywhere, then you could do this:

    class Bootstrap extends Zend_Application_Bootstrap_Base
    {
    "

    I don't see that file and running it returns:

    "Fatal error: Class 'Zend_Application_Bootstrap_Base' not found in C:\joedevon\workspace\application\Bootstrap.php on line 2"

    ===
    In any event, where it's disturbing me is I'd like to write my own queries rather than rely on Zend_Db_Table.

    But since the getInvokeArg('bootstrap') is unavailable in the models, how are you supposed to use the vars that were brought into the Bootstrap from application.ini?

  27. 27 Rob...

    Doh,

    I meant Zend_Application_Bootstrap_Bootstrap rather. I've corrected the above example too.

    It rather depends on how your model depends on your database adapter. If you use Zend_Registry, then you could do:

    
    class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
    {
        public function _initDbAdapter()
        {
            $this->bootstrap('db');
            $dbAdapter $this->getResource('db');
            Zend_Registry::set('dbAdapter'$dbAdapter);
        }
    
        // any other _init methods
    }
    
    

    Regards,

    Rob...

  28. 28 Joe Devon

    Thank you thank you. It was making me crazy. That fixed my problems :) Hopefully I'll be good to go from here on out :)

  29. 29 Mark

    Colleen,

    If you need to register new plugins add the following lines to your bootstrap file. I know others will be looking for the same solution.

    // Create application, bootstrap, and run
    $application = new Zend_Application(
    APPLICATION_ENV,
    APPLICATION_PATH . '/configs/application.ini'
    );

    // ADD THESE 2 LINES
    $bootstrap = $application->getBootstrap();
    $bootstrap->registerPluginResource(new My_Plugin_Class());

    $application->bootstrap()
    ->run();

  30. 30 Madarco DevBlog » Blog Archive » Build a Facebook application with Zend Framework

    [...] set up an empty Zend Framework project: you can use the Zend Studio for Eclipse wizard or the new Zend_Tool command line. Use Zend Studio wizard to create an empty Zend Framewrok [...]

  31. 31 zig2na

    Im new to zend framework and I have been able to follow through with the tutorial but I get the following error at the end it:

    Message: No adapter found for Model_DbTable_Customers

    Stack trace:

    #0 E:\sites\metersys\library\Zend\Db\Table\Abstract.php(652): Zend_Db_Table_Abstract->_setupDatabaseAdapter()
    #1 E:\sites\metersys\library\Zend\Db\Table\Abstract.php(286): Zend_Db_Table_Abstract->_setup()
    #2 E:\sites\metersys\application\controllers\IndexController.php(17): Zend_Db_Table_Abstract->__construct()
    #3 E:\sites\metersys\library\Zend\Controller\Action.php(512): IndexController->indexAction()
    #4 E:\sites\metersys\library\Zend\Controller\Dispatcher\Standard.php(288): Zend_Controller_Action->dispatch('indexAction')
    #5 E:\sites\metersys\library\Zend\Controller\Front.php(936): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
    #6 E:\sites\metersys\library\Zend\Application\Bootstrap\Bootstrap.php(77): Zend_Controller_Front->dispatch()
    #7 E:\sites\metersys\library\Zend\Application.php(303): Zend_Application_Bootstrap_Bootstrap->run()
    #8 E:\sites\metersys\public\index.php(26): Zend_Application->run()
    #9 {main}

    Request Parameters:

    array(3) {
    ["controller"]=>
    string(5) "index"
    ["action"]=>
    string(5) "index"
    ["module"]=>
    string(7) "default"
    }

  32. 32 zig2na

    I am using zend server 4.0.1 with apache on vista and oracle.

    Thanks.

  33. 33 Ashley Broadley

    This is a fantastic tutorial. It gives you that extra bit of understanding compared to the Quickstart. Im very new to ZF and I am eager to learn more. I'm wondering if there will be another tutorial that makes use of authentication and some kind of administration module (i.e a blog?). You've done a great piece of work here though! Two thumbs up!

  34. 34 Rob...

    zig2na,

    What is in your config file?

    Regards,

    Rob...

  35. 35 zig2na

    Rob,

    Thanks for your quick response. Fortunately, I have been able to resolve it.
    I was using the following db strings:

    database.db.adapter = Pdo_Oci
    database.db.params.host = 192.168.1.10
    database.db.params.username = avrladmin
    database.db.params.password = nasa
    database.db.params.dbname = mavrl
    database.db.params.port = 1522

    instead of:

    resources.db.adapter = Pdo_Oci
    resources.db.params.host = 192.168.1.10
    resources.db.params.username = avrladmin
    resources.db.params.password = nasa
    resources.db.params.dbname = mavrl
    resources.db.params.port = 1522

    I copied it from one of my trials.

    Cheers!

  36. 36 Keith

    Has anyone figured out how to separate controllers within the Boostrapper in ZF 1.8?

    I have this in 1.7:

    $front = Zend_Controller_Front::getInstance();

    $front->setControllerDirectory(array(
    'admin' => '../application/admin/controllers',
    'default' => '../application/default/controllers'
    )
    );

    I know I can create an "AdminController" in my "top level" directory that contains all of the admin tools but that would get quite large with several actions.

    This way administrative tools can be kept separate from the public side of the site (in "default"). Has anyone solved this issue?

    Thanks in advance.

  37. 37 ramco

    Hi
    I have an error

    my ini file looks like

    resources.db.adapter = Pdo_Oci
    resources.db.params.host = localhost
    resources.db.params.username = dd
    resources.db.params.password = dd
    resources.db.params.dbname = xe

    My Albums
    An error occurred
    message ?>
    Exception information:

    Message: exception->getMessage() ?>
    Stack trace:

    exception->getTraceAsString() ?>

    Request Parameters:

    request->getParams()) ?>

  38. 38 zig2na

    Try this with oracle adapter and note the dbname line.

    resources.db.adapter = oracle
    resources.db.params.host = 127.0.0.1
    resources.db.params.dbname = 127.0.0.1/xe
    resources.db.params.username = crm
    resources.db.params.password = crm
    resources.db.params.port = 1521

  39. 39 Rob...

    Keith,

    I use a separate module for administration controllers.

    Regards,

    Rob...

  40. 40 GrapeApe

    Thanks for the great tutorial!

    Can the config.ini be used to specify multiple databases? My application uses 2 DBs and it doesn't appear the DB resource can handle multiple databases specified in the ini in any way shape or form.

    I know I can create a new "DBs" resource and have that handle an array of db resources, but is that the best practice?

  41. 41 racmo

    zig2na,
    thanks for your advice. I' ll try .
    If is the table in different schema. What is change in config.ini file?

  42. 42 zig2na

    racmo,
    XE uses your username to select schema provided all the other details given are correct and its able to talk to the XE listner.

  43. 43 ramco

    zig2na,
    actually apache connect to database I saw entris in the listener.log. But the error stil goes on.
    my other question is
    if table's owner different schema from my provided username, how can i select the table? thanks.
    best regards.

  44. 44 zig2na

    ramco,
    your username serves as your schema in XE. But you have to use 'localhost/xe' in your connect as the dbname instead of your actual username which doubles as the schema.

  45. 45 Can´t load models - Zend Framework Forum

    [...] load models Hi there, I'm trying to follow the tutorial in Akra's DevNotes Tutorial: Getting Started with Zend Framework 1.8 but with little sucess! When I get to part that I need to add the code: public function [...]

  46. 46 ramco

    Hi, My problem is all identifier is in "" . oracle support uppercase identifier by default. So, how can implement CASE_FOLDING option in ini file to use db connection? is any suggestion. thanks.

  47. 47 Umair cheema

    Hi,
    It's really a nice tutorial. I am doing something wrong in setting up the path.
    I have successfully set a path and created a project using command
    zf create project xyz
    Now, i need to setup actions in controllers:
    According to tutorial i can do it by using command:
    zf create action add index
    but to do this i should be in xyz/application or xyz directory (not sure ). When i go in directory through command prompt and write the command it gives error that
    "PHP.exe is not recognized as internal or external command"
    And definitely it is correct because php.exe is in c:\php folder instead of c:\php\xyz folder

    Can anybody tell me how can i set actions in C:\php\beta\application\controllers\IndexControlle r.php
    I will really be very thankful to you.
    Regards,
    Umair

  48. 48 Breen Liblong

    Hi Rob,

    Very nice tutorial! I'll definitely checkout your book.

    FYI, the latest version of the pdf (v1.6.2) is missing a section at the top of page 6.

    The previous version of the pdf (v1.5.2) had the following segment (before the sentence fragment) at the top of page 6:

    By default, Zend Framework’s controller reserves a special action called index as a default
    action. That is, for a URL such as http://localhost/zf-tutorial/public/news/
    the index action within the news controller will be executed. There is also a default controller
    name should none be supplied. It should come as no surprise

  49. 49 zig2na

    ramco,

    Try this:

    resources.params.options.caseFolding = caselower

  50. 50 Luciano

    hello,
    Great tutotrial! It all works and the explanations are very good.
    My only question is why did you get the view from the layout:

    $this->bootstrap('layout');
    $layout = $this->getResource('layout');
    $view = $layout->getView();

    as directly getting the view as they show on the zends quick start guide?

    $this->bootstrap('view');
    $view = $this->getResource('view');

    Does it have some benefit?
    thanks!
    Luciano

  51. 51 sims

    Thanks Rob for the tutorial and answers and everyone for your comments. I learned a lot just reading the comments section. I didn't even know ZF has changed since 1.8. I like to use best practices when coding. So it was confusing to see all the differing examples and ways of doing things. Now off to read more.

    Cheers!

  52. 52 Rob...

    Luciano,

    In my tutorial, I don't create a view resource within the bootstrap class or application.ini file.

    Given that you can collect the view from the layout, and I needed to bootstrap the layout anyway, it made sense to grab the view that way.

    Regards,

    Rob...

  53. 53 Pablo

    Hi Rob and thanks for the tutorial.

    I'm having a problem, just added the actions for the IndexController.php via terminal console fine, but when I try to test the URL of the action.. example:

    http://localhost/zf-tutorial/public/index/edit

    I'm getting a 404 Error from Apache, I've been trying to figure out what's going on but I couldn't, a little of help would be appreciated :)

    Thanks in advance!

  54. 54 Pablo

    Ok it's solved

    I just forgot to add AllowOverride All in the httpd.conf for the directory of my project, all is working fine now :-)

  55. 55 ramco

    Zigna,
    thanks for your advice.
    I used this params

    db.params.options.autoQuoteIdentifiers = 0

    It solves one of my problem. But this case, ID column is must be uppercase (ID). But in the sample code the identifier written by lowercase (id), I tried your advice but column identifiers still return with uppercase.

  56. 56 Mohamad A

    I am newbie to Zend framework, while trying your code i got the below error, please guide

    Fatal error: Class 'Models_DbTable_Albums' not found in /var/www/zend_site/application/controllers/IndexController.php on line

  57. 57 khem raj

    Thanks Rob for the tutorial and answers and everyone's comments.But I want to know how We can run Project with "http://localhost/myname" without typing public folder.

  58. 58 Petar

    Hi Rob, guys,
    I am kind of new to ZF, but keen to learn it. So i grabbed the tutorial and ZF 1.8.1 and tried the tutorial both on Win and Ubuntu servers. So I have to say I had very strange and frustrating initial results. On windows i had no bootstrap.php(lower case) file at all and noting in index.php but require_once "bootstrap.php", and as nothing in the tutorial mentioned that something should be done about that I assumed it is ok. It wasn't. Anyway downloading the code and comparing to what I have I understood that I am way off. By pasting the missing bootstrap content everything came to place. On contrary on Ubuntu Zend_Tool created a lot of bootstraping and a default module, all different again from what is used in the tutorial. I am sure that with some adaptation the tutorial will work just fine with the default configuration from Zend_Tool but for a newbie like me it is quite a struggle to get up and running without a clue that something should be changed in the default settings. Other then that it is a great introduction to ZF, and I will probably by the second edition of ZFiA since I heard that there are some errors there too still.

  59. 59 Petar

    Edit to my previous comment - it seems that the problem is not in Zend_Tool, but zend studio which i desided to use for the tutorial, when you make a zf project in zs it overwrites a lot of stuff in your project structure.

  60. 60 Ashley Broadley

    Petar,

    You would need to setup a virtual host within apache (don't know if you are using apache). Search online. there are plenty of good resources for it.

  61. 61 Ashley Broadley

    sorry previous post was meant for khem raj not Petar.

  62. 62 KhemRaj

    Hi,
    I want to solve this problem without using Virtual Host Please Help me.

  63. 63 Rob...

    KhemRaj,

    Place your index.php file in the root directory and modify paths appropriately.

    Regards,

    Rob...

  64. 64 Oleg Lobach

    Hi Rob,
    I found a syntax error - bottom of page 3, DocumentRoot must be '/var/www/html/zf-tutorial/public', but in manual '/var/www/html/z-ftutorial/public'

    With best regards...

  65. 65 Rob...

    Thanks Oleg :)

    Rob...

  66. 66 khem Raj

    hi,
    Thanks for reply Please tell me how we can set the appropriate path after placing index.php in root please explian in detail.
    Thanks.

  67. 67 Jim

    Hey,

    I'm trying to do your tutorial 'Getting started with Zend Framework' Document Revision 1.6.2 and I've come to page 13 of 17. When trying to view the index page I'm getting the following error:

    Notice: Undefined variable: moduleLoader in /Applications/MAMP/htdocs/zf-tutorial/application/Bootstrap.php on line 10

    Fatal error: Uncaught exception 'Zend_Controller_Response_Exception' with message 'Cannot send headers; headers already sent in /Applications/MAMP/htdocs/zf-tutorial/application/Bootstrap.php, line 10' in /Applications/MAMP/htdocs/zf-tutorial/library/Zend/Controller/Response/Abstract.php:281 Stack trace: #0 /Applications/MAMP/htdocs/zf-tutorial/library/Zend/Controller/Response/Abstract.php(299): Zend_Controller_Response_Abstract->canSendHeaders(true) #1 /Applications/MAMP/htdocs/zf-tutorial/library/Zend/Controller/Response/Abstract.php(727): Zend_Controller_Response_Abstract->sendHeaders() #2 /Applications/MAMP/htdocs/zf-tutorial/library/Zend/Controller/Front.php(974): Zend_Controller_Response_Abstract->sendResponse() #3 /Applications/MAMP/htdocs/zf-tutorial/library/Zend/Application/Bootstrap/Bootstrap.php(77): Zend_Controller_Front->dispatch() #4 /Applications/MAMP/htdocs/zf-tutorial/library/Zend/Application.php(328): Zend_Application_Bootstrap_Bootstrap->run() #5 /Applications/MAMP/htdocs/zf-tutorial/public/index.php(26 in /Applications/MAMP/htdocs/zf-tutorial/library/Zend/Controller/Response/Abstract.php on line 281

    I'm running a MAMP server on Mac OS X.

    Can anyone help me? Thanks!

  68. 68 Jim

    Hey,

    now I'm having another problem.
    Whem I'm trying to view http://localhost:8888/zf-tutorial/public/

    of my MAMP on Mac OS installation
    it says:

    Add new album
    An error occurred
    Application error
    Exception information:

    Message: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'zf.Model_DbTable_Albums' doesn't exist
    Stack trace:

    #0 /Applications/MAMP/htdocs/zf-tutorial/library/Zend/Db/Statement.php(283): Zend_Db_Statement_Pdo->_execute(Array)
    #1 /Applications/MAMP/htdocs/zf-tutorial/library/Zend/Db/Adapter/Abstract.php(467): Zend_Db_Statement->execute(Array)
    #2 /Applications/MAMP/htdocs/zf-tutorial/library/Zend/Db/Adapter/Pdo/Abstract.php(235): Zend_Db_Adapter_Abstract->query('DESCRIBE `Model...', Array)
    #3 /Applications/MAMP/htdocs/zf-tutorial/library/Zend/Db/Adapter/Pdo/Mysql.php(156): Zend_Db_Adapter_Pdo_Abstract->query('DESCRIBE `Model...')
    #4 /Applications/MAMP/htdocs/zf-tutorial/library/Zend/Db/Table/Abstract.php(727): Zend_Db_Adapter_Pdo_Mysql->describeTable('Model_DbTable_A...', NULL)
    #5 /Applications/MAMP/htdocs/zf-tutorial/library/Zend/Db/Table/Abstract.php(770): Zend_Db_Table_Abstract->_setupMetadata()
    #6 /Applications/MAMP/htdocs/zf-tutorial/library/Zend/Db/Table/Abstract.php(923): Zend_Db_Table_Abstract->_setupPrimaryKey()
    #7 /Applications/MAMP/htdocs/zf-tutorial/application/models/DbTable/Albums.php(24): Zend_Db_Table_Abstract->insert(Array)
    #8 /Applications/MAMP/htdocs/zf-tutorial/application/controllers/IndexController.php(33): Model_DbTable_Albums->addAlbum('The Killers', 'Day and Age')
    #9 /Applications/MAMP/htdocs/zf-tutorial/library/Zend/Controller/Action.php(512): IndexController->addAction()
    #10 /Applications/MAMP/htdocs/zf-tutorial/library/Zend/Controller/Dispatcher/Standard.php(288): Zend_Controller_Action->dispatch('addAction')
    #11 /Applications/MAMP/htdocs/zf-tutorial/library/Zend/Controller/Front.php(936): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
    #12 /Applications/MAMP/htdocs/zf-tutorial/library/Zend/Application/Bootstrap/Bootstrap.php(77): Zend_Controller_Front->dispatch()
    #13 /Applications/MAMP/htdocs/zf-tutorial/library/Zend/Application.php(328): Zend_Application_Bootstrap_Bootstrap->run()
    #14 /Applications/MAMP/htdocs/zf-tutorial/public/index.php(26): Zend_Application->run()
    #15 {main}

    Request Parameters:

    array(7) {
    ["controller"]=>
    string(5) "index"
    ["action"]=>
    string(3) "add"
    ["module"]=>
    string(7) "default"
    ["id"]=>
    string(0) ""
    ["artist"]=>
    string(11) "The Killers"
    ["title"]=>
    string(11) "Day and Age"
    ["submit"]=>
    string(3) "Add"
    }

    databasename is: zf
    tablename is: albums
    I'm using default username/password: root

    can anyone help me? Thanks!

  69. 69 Jim

    It looks like it's working now. I've removed a "?>" at the end of Albums.php
    Thanks anyway.

  70. 70 T3ch

    I followed the tutorial and everything works correctly, but When I modify your 4 record, I see:
    It\'s Not Me, It\'s You
    and not:
    It's Not Me, It's You

    There is a problem with quote...

  71. 71 Rob...

    T3ch,

    Turn off magic_quotes_gpc

    Regards,

    Rob...

  72. 72 T3ch

    Thank's Rob. Your tutorial and your site are very usefully.

  73. 73 Erich

    Rob,

    Great tutorial!

    I was running some memory tests on this application, and I noticed that most pages use about 7 MB of memory for each script. I was using memory_get_peak_usage(). Isn't that a bit high for a web app such as this? I am new to ZF, so I may have no clue what I am talking about.

    Thanks, Erich

  74. 74 Marco

    Hey. I'm having some trouble running zf.sh. It leaves me with the following notification:

    /usr/local/ZendFrameworkCli/bin/zf.sh: 44: php: not found

    Any advice on how to solve this?

  75. 75 Erich

    Marco,

    I had the same issue. To fix it, run phpinfo() and check to make sure that your "include_path" is pointing to the correct directory. Make sure the "Zend" folder from the zend framework download is in that folder as well. That took care of the issue for me.

  76. 76 Marco

    Erich, thank you for your help. I havent been able to fix it on my localhost however. So I decided to put it on my 1and1 hosting space. That however leaves me with another error:

    (uiserver):u47756847:~/ZendFramework-1.8.2/bin > zf.sh show version

    Parse error: syntax error, unexpected T_STRING, expecting '{' in /path_to_my_hosting_directory/ZendFramework-1.8.2/library/Zend/Tool/Framework/Client/Console.php on line 63

    I'm quite sure this is due to an older php version (4.*), since the line being mentioned (63) contains 'implements' (which is php 5 only).

    1And1 does support php5 by using a htaccess file. So I tried creating a .htaccess file (AddType x-mapp-php5 .php) and it works fine when visiting pages through my browser. However when running the .sh file through SSH it still gives the error message. Any other solutions?

    Thanks in advance!

  77. 77 T3ch

    @Marco
    you must write to 1and1 and not here. Who manages the server can respond to your request

  78. 78 Erich

    I agree with T3ch. There a lot of additional variables that come into play, especially with shared hosting. Honestly, Zend Tool is nice for some of the busy work at the start of the project, but if you're just starting to learn ZF, you can just download the tutorial and start playing with it.

  79. 79 Colandy

    Have an issue, don't think this is unique to your tutorial as I get same on Quickstart tutorial. My setup is:

    Vista
    Apache - 2.2.11
    PHP - 5.2.9-2
    MySQL - 5.1.3

    The error is as follows:

    My Albums
    An error occurred
    message ?>
    Exception information:
    Message: exception->getMessage() ?>

    Stack trace:
    exception->getTraceAsString() ?>
    Request Parameters:
    request->getParams()) ?>

    Any Idea's ?!??

  80. 80 eben

    very helpful stuff.
    i use module but i can't seem to get the autoloader to work. some pointers would be helpful.

  81. 81 Buck

    Hello

    Tutorial is great, but i have still problem with adding new modules into tutorial code.

    Is there anyone who could public tutorial code extended about (for example) two simple modules?

    I'm searching web about it but there is no better tutorial than your's Rob but you give us only default module without IDEA of extending tutorial code for new modules.

    Please help me (and many zf users) with some advice.

  82. 82 khemRaj

    Hi,
    When I am placing index.php in root directory Then find folowing error.
    Fatal error: Uncaught exception 'Zend_Config_Exception' with message 'parse_ini_file(D:\xampp\htdocs\zf1.8application\configs\application.ini) [function.parse-ini-file]: failed to open stream: No such file or directory' in D:\xampp\htdocs\zf1.8\library\Zend\Config\Ini.php:184 Stack trace: #0 D:\xampp\htdocs\zf1.8\library\Zend\Config\Ini.php(125): Zend_Config_Ini->_loadIniFile('D:\xampp\htdocs...') #1 D:\xampp\htdocs\zf1.8\library\Zend\Application.php(320): Zend_Config_Ini->__construct('D:\xampp\htdocs...', 'development') #2 D:\xampp\htdocs\zf1.8\library\Zend\Application.php(78): Zend_Application->_loadConfig('D:\xampp\htdocs...') #3 D:\xampp\htdocs\zf1.8\index.php(18): Zend_Application->__construct('development', 'D:\xampp\htdocs...') #4 {main} thrown in D:\xampp\htdocs\zf1.8\library\Zend\Config\Ini.php on line 184

    Thanks.

  83. 83 Basic Database + zend framework « Zframework’s Blog

    [...] click here OR [...]

  84. 84 Joe Devon

    Rob,

    I see you're using public function() in the Bootstrap, but the quickstart makes them protected. Was there a particular reason to make them public?

    Thanks.

  85. 85 Marcus

    Great tutorial! Helped me a lot!!!

    I really had problems finding a tutorial to get started with Zend. Maybe they should offer more tutorials like this - the official Zend quickstart tutorial doesn't really help at all...

    So thanks for this. Looking forward to an updated version of your Zend_Auth tutorial ;-)

  86. 86 Rob...

    Marcus,

    They should be protected.

    Regards,

    Rob...

  87. 87 Joe Devon

    I think you meant me, but thanks Rob ;)

  88. 88 Joe Devon

    Sorry, I have another question. In your model, you are extending Zend_Db_Table rather than Zend_Db_Table_Abstract as the manual and quickstart instructions. When are you supposed to use the former and when the latter?

  89. 89 Rob...

    Joe,

    Zend_Db_Table_Abstract is better choice. I'll update the tutorial.

    Regards,

    Rob...

  90. 90 Sebastian Mantilla

    It seems to me as if in the PDF there are some lines missing.

    Look for example at the beginning of page 6, the first phrase is incomplete it is missing something at the beginning.

    Thanks for the tutorial.

  91. 91 Rob...

    Sebastian,

    Yeah there is :( I'll roll up a new one soon.

    Rob...

  92. 92 Joe Devon

    Rob & anyone still reading this far into the comments :)

    I just wanted to mention that I stopped using the registry to hold the dbAdapter. It turns out if you add this line to your application.ini file (if you only connect to one database as most probably do):

    resources.db.isDefaultTableAdapter = true

    then in your model you can just do:
    $this->_dbAdapter = Zend_Db_Table::getDefaultAdapter();
    and remove the whole section in the bootstrap that initializes your dbAdapter and puts it in the registry.

  93. 93 Michael B.

    This is the best tutorial which i could found on the web!

    Maybe someone can help me. I got

    Fatal error: Uncaught exception 'Zend_Application_Bootstrap_Exception' with message 'Resource matching "layout" not found'

    after completing 12 page of tutorial.
    Im relatively new to PHP, and no wonder, to ZF...

  94. 94 Joe Devon

    Michael,

    I agree. Rob's book and online tutorials are a Godsend.

    Try adding these lines to your application.ini:

    resources.layout.layout = "layout"
    resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
    resources.view[] =

  95. 95 Dodo : Introduction | ThreadAffinity

    [...] Framework (ZF from here on). For those just starting out with ZF, you definitely want to check out Rob Allen's tutorials and blog posts if you haven't already. Rob's examples are some of the best out there [...]

  96. 96 Michael B.

    Thanks, Joe!
    Now I have a new errors %)
    After fixing some of them I stuck with another one:
    Fatal error: Uncaught exception 'Zend_Loader_PluginLoader_Exception' with message 'Plugin by name 'BaseUrl'

    I have checked my files but without success. They all seems identical to what I can see in tutorial. I know that I made a mistake, but just doesnt see them

  97. 97 Michael B.

    Oh, I made a wrong cut. The full text:

    Fatal error: Uncaught exception 'Zend_Loader_PluginLoader_Exception' with message 'Plugin by name 'BaseUrl' was not found in the registry

  98. 98 David

    Hello, Rob, you doing a great job, helping others to understand what is ZF is =)
    I want to do a translate of your "Tutorial: Getting Started with Zend Framework 1.8" and place it on this page. Is it real? do you need this?
    mail me please if you are interesting with it.
    p.s.
    mailto: enleonkiller (on) google mail.

  99. 99 David

    oh sorry, my fault.
    p.p.s. i want to translate it into russian.

  100. 100 Rob...

    David,

    I'd love it if you do a translation! Give it a few days though until I upload the next one with some typo fixes in it.

    Feel free to send it to me in PDF and I'll host it.

    Rob...

  101. 101 Joe Devon

    Hi Michael,

    Hmmm, I have no idea what that error means. Hopefully Rob will figure it out or another guru will see it & comment.

  102. 102 Scott Biggart

    Ramco,

    I too wanted to have the CASE_FOLDING attribute set in the application.ini file, this is what worked:

    resources.db.params.options.caseFolding = 2

    where 'caseFolding' is the value once the Zend_Db::CASE_FOLDING constant is evaluated and the int 2 is the value once the Zend_Db::CASE_LOWER constant is evaluated

    for reference, CASE_UPPER = 1

  103. 103 Jim

    Hi,

    I've tried your tutorial and it's works fine. Now I'm curios how I could read the record from the database in reverse order. So if I add a album, I want it to show up on top instead of at the bottom of the tabel.

    How can this be done?

  104. 104 Nils Becker

    Hi Rob,

    great tutorial - helped me a lot.

    One thing that doesn't work in my test.

    In my layout.phtml file the title is not displayed:
    escape($album->title); ?>
    The headTitle is displayed correct.

    Any ideas whaht i've made wrong?

    Thanks,
    Nils

  105. 105 Nils Becker

    Sorry the line of code in my post is wrong. The correct line is on page 10 the line in the h1 tag.

  106. 106 Alex Tech Adventures || Zend Framework MVC basics

    [...] The code you are looking at is taken from Akra's DevNotes blog, Getting started with Zend Framework tutorial. [...]

  107. 107 Andrey

    Thank you Rob for this tutorial!
    I feel like i'm lost something.. i need to get request parameters in the bootstrap (like controller name and action name), but Zend_Controller_Request_Http::getModuleName, etc. is empty...

    Can you please help?

    Thank you!
    Andrey

  108. 108 Dodo : Part 1 - Application Design | ThreadAffinity

    [...] the Dodo Introduction post, I recommended staring with Rob Allen's tutorial and the QuickStart guide for those just starting out because they do a better job of going [...]

  109. 109 Kalpesh

    Hi, Rob thanks for your tutorial
    Its Great.
    but i have problem with url having http://localhost/ZEND1.8/public/index/add.
    It is getting me 404 error.
    I also set the AllowOverride none in my httpd.conf file which is as follow :

    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all

    can you help me ?

  110. 110 Dana Elza

    Hello,

    This is THE best tutorial for getting started with ZF. I understood what ws written, and the code worked, no problems at all.

    Now do a Navigation tutorial.

    5 years writing php and always something new to explore.

    Thanks!

  111. 111 Guelmis

    Hi:
    I'm kind of new using Zend, and I found a tutorial but I couldn't make my application work properly, it launches errors constantly, could anyone give me a link or anything so I can find an example that works with Zend 1.8 and has all the initial configuration of the application.ini, the .htacces and the boostrap.php???????
    It's really important.

  112. 112 Dave Poon

    Your tutorial is so good, easy to follow and understand, I have read many tutorials on the Internet, but the way of writing is so complicated, thank you so much.
    BTW, I just bought your book, just read a few chapters, I love it, thanks.

  113. 113 Fabio Rehm

    really nice tutorial!
    thanks for doing it.

  114. 114 hex

    great tutorial, very well written.thank you very much

  115. 115 Miriam

    Hi!

    I'm very new in ZendFramework and I have this problem I dont know what should configure for work with Zend_Db_Table_Abstract because if I create my class in this way :

    class Clientes extends Zend_Db_Table_Abstract and in my controller I create an object
    $Clientes = new Clientes();

    when I try my application the output is
    Fatal error: Class 'Clientes' not found in /home/miriam/zend_proyects/new_zend/application/controllers/IndexController.php on line 21

    and the line 21 is where I instance the object.

    What should I add for get it work.

    My boostrap file is this:

    '',
    'basePath'=> APPLICATION_PATH));
    return $moduleLoader;

    }

    function _initViewHelpers()
    {
    $this->bootstrap('layout');
    $layout = $this->getResource('layout');
    $view = $layout->getView();

    $view->doctype('XHTML1_STRICT');
    $view->headMeta()->appendHttpEquiv('Content-Type', 'text/html;charset=utf-8');
    $view->headTitle()->setSeparator(' - ');
    $view->headTitle('Zend Framework Tutorial');
    }

    and my index.php is this

    bootstrap()
    ->run();

    Thanks in advance.

The views expressed in these comments are not the views of the publisher. However, we believe in the rights of others to express their legitimate views and concerns. Any legitimate complaint emailed to rob@akrabat.com will be seriously considered and the post reviewed as desirable and necessary.

Leave a Reply

Buy now!