Tutorial: Getting Started with the Zend Framework 1.0

This tutorial is intended to give a very basic introduction to using the Zend Framework to write a simple database driven application.

NOTE: This tutorial has been tested on version 1.0.0 of the Zend Framework. It stands a very good chance of working with later versions. It is unlikely to on any version prior to version 1.0.0 due to dependency on the ViewRenderer action helper.

English version: Dowload the PDF (v1.4.5).
Simplified Chinese version by Jason Qi (offsite): Visit Jason's download area.
French version by Guillaume Rossolini (offsite): Débuter avec le Zend Framework.
Polish version by Kubek Bartosz (offsite): Pierwsze kroki z Zend Framework.
Russian version by Alex Musayev (offsite): Russian Translation (PDF)
Czech version by Petr Parimucha (offsite): CzechTranslation
Brazillian Portuguese version by Ricardo Klein (offsite): Getting Started with Zend Auth_pt-BR
Latvian version by Ingus (offsite): Ievads Zend Framework
Slovakian version by Igor Hlina (offsite): Začíname so Zend Frameworkom – tutoriál

Translations for previous versions of this tutorial:
Brazillian Portuguese version by Adler Medrado: Iniciando com Zend Framework (1.3.0).
German translation by Daniel Messer: Einstieg in das Zend Framework: PDF (v1.3.0).
Danish translation by Stig Benning: I gang med Zend Framework: PDF (v1.3.4).
Spanish translation by Claudio Cossio (offsite): Desarrollo de Aplicaciones con Zend Framework: PDF (v1.3.3).
Indonesian version by Riki Risnandar: Tutorial Awal dengan Zend Framework PDF (v.1.2.3)
Italian version by Fabrizio Frosali: Primi passi con il Framework Zend (off site).

Code

The associated code is available:

Changelog

1.4.5
Made the dependencies on mod_rewrite and .htaccess files more obvious.
1.4.4
Use createRow() to create an "empty" album as noticed by Terry Stalker. Also, fixed reference to $_SERVER[’REQUEST_METHOD’] as reported by balu!
1.4.3
Further updates so that the flow makes sense!
1.4.2
Updates to support version 1.0.0. of the Zend Framework
1.4.1
Updates to support version 1.0.0. RC2of the Zend Framework
1.4.0
Updates to support version 1.0.0. RC1 of the Zend Framework.
1.3.4
Improvements to the English found by Guillaume Rossolini.
1.3.3
Another typo! Found by Wayne Roesner.
1.3.2
More typos fixed. Found initially by Ludo, then many others ;)
1.3.1
Now using isPost() as suggested by sleek. Also filed typos found by Jason Qi.
1.3.0
Significant reworking to support version 0.9 of the Zend Framework.
1.2.4
Typographical fixes found by Darren Chandler. This version has been tested on 0.8 of the Zend Framework.
1.2.3
Updated notes on which versions of the Zend Framework are supported, now that I've tested on 0.7.
1.2.2
Fixed more typographical and contextual issues found by Jason Qi.
1.2.1
First typo found by Jason Qi.
1.2.0
Updated tutorial for version 0.6 of the Zend Framework.
1.1.1
Fixed setting of the include path.
Fixed multiple typos found by Brendon Kozlowski.
1.1.1
Fixed initiation of the Front Controller in index.php.
1.1.0
Updated tutorial for version 0.2 of the Zend Framework.
1.0.5
Added some troubleshooting information about using setRewriteBase().
1.0.4
Maybe I've finally nailed down the path to IndexController.php!
1.0.3
More minor fixes. Thanks Thanks Holger and Develucas! Added note about only working with 0.1.5.
1.0.2
Typo fix. Thanks Chris!
1.0.1
Multiple minor fixes. Thanks Nathan, Nick, Matthew and everyone else!
1.0
Original version

554 thoughts on “Tutorial: Getting Started with the Zend Framework 1.0

  1. Great tutorial, but I still don't understand how the models work. i.e. when I have a model for some newsposts how can I combine those posts with the right category (that's a different model I think).

    Ow, and at page 11: "$this->actionTemplate" should be "$view->actionTemplate".

    The rest is Great!

  2. Sorry, been away for a few days on holiday (without a computer!)

    I've fixed the links. The changes I made were to the PDF, not the zip file, but I updated the post incorrectly.

    You should now be able to dowload a version 1.0.1 of the PDF.

  3. i have problems in 6th page. When i try to test IndexController with a url like http://localhost/zf_tutorial/index/add i'm notice with:

    Fatal error: Uncaught exception Zend_Controller_Action_Exception with message 'IndexController::norouteAction() does not exist and was not trapped in __call().' in c:arquivos de programasapache groupApachehtdocszf_tutoriallibraryZendControllerAction.php:92 Stack trace: #0 c:arquivos de programasapache groupApachehtdocszf_tutoriallibraryZendControllerAction.php(92): Zend_Controller_Action::__call() #1 c:arquivos de programasapache groupApachehtdocszf_tutoriallibraryZendControllerAction.php(114): IndexController->__call('norouteAction', Array) #2 c:arquivos de programasapache groupApachehtdocszf_tutoriallibraryZendControllerDispatcher.php(185): IndexController->run(Object(Zend_Controller_Dispatcher), Object(Zend_Controller_Dispatcher_Token)) #3 c:arquivos de programasapache groupApachehtdocszf_tutoriallibraryZendControllerDispatcher.php(136): Zend_Controller_Dispatcher->_dispatch(Object(Zend_Controller_Dispatcher_Token), true) #4 c:arquivos de programasapache groupApachehtd in c:arquivos de programasapache groupApachehtdocszf_tutoriallibraryZendControllerAction.php on line 92

  4. I'm going through your tutorial right now, and so far it's awesome. One note though – I've had trouble with the initial mod_rewrite rules for when this app exists in a subdirectory. When I changed the rules to this for the zf-tutorial/.htaccess file it worked:

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

    Is there a better way to do this?
    fyi: I'm running this via Apache 1.3 on Tiger, using PHP 5.1.x

    Thanks!

  5. Hi Dan,

    From what I can tell, the automatic working out of the base URL by the RewriteRouter doesn't work in certain cases.

    There's no real current solution yet, so fixing the rewrite rules seems as good a way as any to me.

  6. Great work! Really got me into working with the Zend-Framework. Thanks!

    One note though: In the 'IndexController' in your 'addAction' you are not setting the id-property of the album, resulting in a "Property not found…"-error in the HTML-page as the value for the hidden Id-field. This is not a problem in the code, since the id-field is not considered when adding an album, but if someone looks at the HTML-code, it's ugly.

    (Running the code on a PHP-5.1.4 with Hardening-Patch.)

  7. hai Rob i'm from holland i vound your tutorial super.I want to ask je of you can make a tutorial with INNER JOIN. Thanks

  8. Hai rob Can i do this:

    $view->homepage = $homepage->fetchAll("SELECT * FROM homepage");

    —————————–

    function indexAction()
    {
    $view = Zend::registry('view');
    $homepage = new Homepage();
    $view->homepage = $homepage->fetchAll();
    $view->homepageactionTemplate = 'homepageIndex.tpl.php';

    $rubrieken = new Rubrieken();
    $view->rubrieken = $rubrieken->fetchAll();
    $view->rubriekenactionTemplate = 'rubriekenIndex.tpl.php';

    echo $view->render('site.tpl.php');

    }

  9. Noury,

    I don't see why not. Obviously, you have to render() both homepageactionTemplate and rubriekenactionTempate from within site.tpl.php.

  10. On page 4, you say: "Note that we do not put in the ?> at the end of the file as it is not needed and leaving it out ca prevent some hard-to-debug errors."

    This is the first time I have heard of this. Where can I find more info on this concept?

  11. I have problem with tutorial.
    its probably in this line: render($this->actionTemplate); ?>

    message is:

    Warning: Zend_View::include(./application/views) [function.Zend-View-include]: failed to open stream: Permission denied in D:new_wampwwwzf_tutoriallibraryZendView.php on line 46

    Warning: Zend_View::include() [function.include]: Failed opening './application/views' for inclusion (include_path='.;./library/;./application/models') in D:new_wampwwwzf_tutoriallibraryZendView.php on line 46

  12. Good looking tutorial although I cannot get anything other than IndexController working.
    I need multiple possibilities for the controller, as mentioned in the tutorial, but not added.

    Example:
    / – uses index controller IndexController.php indexAction method
    /index/add should use IndexController.php addAction method
    /dummy – should use DummyController.php indexAction method
    /dummy/new should use DummyController.php newAction method

    How would you set this up using the router if necessary ?

  13. Hallo rob,
    Would you like to tell me hoe i can use join().
    I don't know where i put join() and how.
    I have a news table and a user table. Every news a written by a user:

    class news extends Zend_Db_Table{}.
    class user extends Zend_Db_Table{}.

    thank you very much
    Nour

  14. Hi,
    I have this error using the tutorial:

    Fatal error: Uncaught exception 'Zend_Db_Adapter_Exception' with message 'The mysql driver is not currently installed' in C:wampwwwzf-tutoriallibraryZendDbAdapterPdoAbstract.php:80 … I didn´t put the stack trace

    I´m in page 14 (version 104)

  15. Rob:
    I already did, I'm using WAMP5, that was the first thing i thought too, but still nothing

    Regards

  16. Rob:
    I could connect to mysql using prado framework, so the driver works
    but still have the same error using Zend

    regards

  17. Thx for the tutorial, helps a lot because it gives you the basics of understanding how this framework works, not very in-depth… initially i had v.10 (which had the bug of $this instead of $view, and only after i've figured out myself i got to see v101). Still, sometimes I have doubts about real applications needsing the whole structure, because it could be a terrible overload on a machine to have, let's say, 300 sites (simple, small ones) running with zend framework. Some preliminary tests showed me a good degree of slowing down everything, and a pretty high increasing of memory consumption. It is obviously, extremely good for organizing everything very well, and all maintenance/upgrades. And very good to know all the things in order to have a better overview of large apps, but probably most of the people will not even take the time to look for a tutorial, and, in case they don't find one like yours, they'll give up zend framework, and continue using some older ones, tested and known.

    Regards,
    Dragos

  18. Well, another error I've found right now on page 13, under "Listing Albums". It says: zf-tutorial/application/views/IndexController.php with the lines function __construct()…. Well, it happens that this is not the controller we're looking for, but instead, that controller resides in /application/controllers/IndexController.php
    Same thing couple of lines below, again, where we add the code for instantiating and fetching the albums list… Please correct the tutorial, man, as it will never bring people to something usable (but I still appreciate a lot your effort, so let's make it work as well as it could).

    Regards
    Dragos

  19. oops, sorry, I've only now found the v1.0.4 :) .. it was too visible to see it, my apologies please

  20. Hi Dragos,

    Thanks for the comments. As you can see, I've tried to sort out the typos and I'm vaguely hopeful that 1.0.4 is typo free. Of course, if you find anything, please let me know and I'll fix it!

    Regards,

    Rob…

  21. same problem as Comments#29 (but on linux), variable was empty

    I changed
    $this->actionTemplate = 'indexIndex.tpl.php';
    into
    $view->actionTemplate = 'indexIndex.tpl.php';

    and it works fine…

  22. Hi there,

    I want to add my thanks for a great tutorial. I do have a problem however. Exactly the same error as described in comment 12. I do have the IndexController.php file setup as in the tutorial and have a function called AddAction in the Controller class.

    I can access zf_tutorial/ which echos 'in IndexController::indexAction()' but zf_tutorial/index/add or zf_tutorial/index/edit result in the error:

    Fatal error: Uncaught exception 'Zend_Controller_Action_Exception' with message 'IndexController::norouteAction()…etc

    I'm running php PHP 5.1.6 and Apache 1.3 on Mac OSX 10.4.7 with Zend Framework 0.1.5

    I've double checked everything and can't figure it out. Would appreciate any suggestions.

    Thanks

  23. Problem solved. It was to do with having my application in a subfolder although I tried all of the fixes suggested above and nothing seemed to work. In the end I added this to the bootstrap file:

    $route->setRewriteBase('/~my_osx_username/zf_tutorial');

    Working fine now

  24. Hi Dave,

    From what I've learnt so far, I think that setRewriteBase() is the most reliable way to get rewrite routing working. I'll update the tutorial soonish to reflect this.

    Regards,

    Rob…

  25. Hi Rob!!
    I have the same problem as Dave described.
    Fatal error: Uncaught exception 'Zend_Db_Adapter_Exception' with message 'The mysql driver is not currently installed' in C:wampwwwzf_tuttlibraryZendDbAdapterPdoAbstract.php:8..etc
    where should I make the changes ??
    Thnx for a great tut.

  26. Done!! I use WAMP, I made the changes in wamp/PHP/php.ini and it didn't work. But when I made the changes in C:wampApache2binphp.ini i start to work .
    Thnx again ..
    Hasan..

  27. Posting this in case anyone else has similar difficulties…

    Apache/2.0.59 (Unix) Server
    PHP Version 5.1.6
    MySQL API 5.0.22

    I am stuck at page 6 in the tutorial (zf-tutorial/application/controllers/IndexController.php).

    I am having the same fatal error as some other folks (see mssg 12 & 48), but their solutions in my environment haven't removed the error.

    FYI, I just reviewed my directory structure and code against your Subversion repository. No difference for the pertinent components/code that I see (but am sure there is something).

    In index.php.addRoute(), I can change the default action to get each function to display its message as the default or Index action (wierd).

    That is,
    if:
    $route->addRoute('edit', ':controller/:action/id/:id',array('controller' => 'index','action' => 'index'));
    then:
    1. requesting wwwroot(aka html)/zf-tutorial displays "in IndexController::indexAction()"
    2. requesting wwwroot(aka html)/zf-tutorial/index displays "in IndexController::indexAction()"
    3. requesting wwwroot(aka html)/zf-tutorial/add encounters norouteAction() – fatal error

    if:
    $route->addRoute('edit', ':controller/:action/id/:id',array('controller' => 'index','action' => 'add'));
    then:
    1. requesting wwwroot(aka html)/zf-tutorial displays "in IndexController::addAction()"
    2. requesting wwwroot(aka html)/zf-tutorial/index displays "in IndexController::addAction()"
    3. requesting wwwroot(aka html)/zf-tutorial/add encounters norouteAction() – fatal error

    So this seems like one of those scope problems that always give me headaches. :-)

    Anyway still reading the manual and going in circles.

  28. Thanks for the response.
    I wasn't clear in my post yesterday and I did not give you a full picture. Sorry.
    My guess is the problem is likely environmental since none of the coding solutions here, Craig Shiflett's site or the Manual seem to get me a proper result.

    To answer your question, 'Yes'. When I try to setRewriteBase, this message results"
    mod_rewrite: maximum number of internal redirects reached. Assuming configuration error. Use 'RewriteOptions MaxRedirects' to increase the limit if neccessary.

    The operations seems to want more than 10 redirects?
    MaxRedirects is 10 which is the most this server allows apparently. Guess I can submit a support ticket to find out more.

    Thanks.

  29. Are the .htaccess files with 'deny from all' even necessary? Wouldn't the 'RewriteRule .* index.php' catch any access to the application and libraries directories and interpret the request through the index.php file, or am I missing something?

  30. Justin,

    You are almost certainly right as there aren't anre RewriteCond's to allow through files that exist on the hard drive.

    Regards,

    Rob…

  31. Hey Rob, Great tutorial.

    I'm having an issue however:
    Fatal error: Uncaught exception 'Zend_Exception' with message 'File "Album.php" was not found.' in /var/www/zend.onlinedyno.com/library/Zend.php:190

    I first thought maybe I had set things up incorrectly as I went through your tutorial but then I downloaded your code and reset config.ini to my values and I get the same error.

    Any thoughts?

    Thanks,
    Matt

  32. Quick followup. I was able to get past my error by adding the following to my .htaccess
    php_value include_path .:/var/www/zend.onlinedyno.com/zf-tutorial/application/models/

    Doesn't seem like the best solution so let me know if I'm missing something obvious.

  33. Hey Rob, I swear I'm not trying to spam your blog but here's a solution I found that works for $baseUrl. I think it should work as long as your application is in the root of a site.

    $baseUrl = substr($_SERVER['DOCUMENT_ROOT'],strrpos($_SERVER['DOCUMENT_ROOT'],'/'));

  34. Hi Matt!

    In your index.php you should have included application/models into the include-path with a statement like:

    set_include_path('.' . PATH_SEPARATOR . './library/'
    . PATH_SEPARATOR . './application/models'
    . get_include_path());

    I'm wondering if the set up you are using means that when running index.php, the current working directory is not the same directory as the one that index.php is in.

    To check, change this bit to:

    set_include_path('.' . PATH_SEPARATOR . './library/'
    . PATH_SEPARATOR . dirname(__FILE__) . '/application/models'
    . get_include_path());

    and see if that works.

    It still seems that getting the right baseURL is very much system dependant :(

    Regards,

    Rob…

  35. Hey Rob,

    I'm a bit perplexed. After working with it a bit and removing my php_value from .htaccess here's what I ended up with:

    set_include_path(get_include_path().PATH_SEPARATOR.'./library/'.PATH_SEPARATOR. './application/models');

    And then if I echo get_include_path() afterwards I get:
    .:/usr/share/php:./library/:./application/models

    The original set include gave me a get_include_path() of:
    .:./library/:./application/models.:/usr/share/php

    I don't see the difference other than the order but it absolutely won't work with the original path and it works flawlessly with my modified one. Ah wait… There's an extra . after models in the original. That's what is breaking it. We need another PATH_SEPARATOR in there so it becomes:

    set_include_path('.' . PATH_SEPARATOR . './library/'
    . PATH_SEPARATOR . './application/models'. PATH_SEPARATOR
    . get_include_path());

    Other than that, your tutorial has really sparked my interest in the framework. I wish it was a bit more mature but they're off to a great start with it!

  36. If anyone else is getting the following error:

    Fatal error: Uncaught exception ‘Zend_Controller_Action_Exception’ with message ‘IndexController::norouteAction() does not exist and was not trapped in __call().’

    Have a look at this revision. Seems to work well for me. The problem seems to occur only when using _redirect() to redirect the user back to the indexAction(). Instead of redirecting, why not just executing it?

    Here's the revised code:
    http://pastebin.com/823169 (Note the highlighted portion.)

  37. Matt,

    What happens then when you just point to your root directory without passing an entire :controller/:action string?

    For example, try http://www.yourdomain.com instead of http://www.yourdomain.com/index/index. The noRouteAction() method should be called, I'd guess. If that is the case, that would render your application unusable for anyone that doesn't know an exact path to your main index. That's precisely what happens when I try the same – unless I have done something wrong here, and I think my code is pretty sound.

    Additionally, I am not very fond of error pages. I chose to redirect to the main index in case of a 404.

    If you are interested, you can take a look at my slightly more complicated example (which uses the Smarty template engine instead of Zend_View) here: http://harbinger.pastebin.com/823168

    Keep in mind that this script is work in progress and don't be too harsh in juding. :)

  38. I think the problem is that there's a bug in the tutorial, right at the bottom of index.php:

    $controller->run('./application/controllers');

    should be:

    $controller->setControllerDirectory('./application/controllers');
    $controller->dispatch();

    Otherwise, the normal router is used rather than the the rewrite one.

    I've updated the PDF and the zip file.

    Regards,

    Rob…

  39. Thanks, Rob. Looks like we all missed this one. It's so hard keeping it straight, though, when the design of the application changes like this and the developers are slow to update documentation. Still… Zend Framework is living up to the hype.

  40. This is not the venue, but my asking stems from the goodness of this tutorial.

    First though…
    Thanks for this tutorial; it has been such a great help (education, motivation, etc.)!

    It works so well in my Unix test environment that I took the plunge and set up a local WAMP environment.
    Voila! The same code would not work under Windows. I'd get an Undefined Property error on the $config object.

    Here is the offending code that works pefectly in UNIX, but not in Windows:

    db->adapter, $config->db->config->asArray());
    Zend_Db_Table::setDefaultAdapter($db);
    ?>

    In a ZF manual code sample, I found that Config.php and Config/Ini.php are required
    (http://framework.zend.com/manual/en/zend.config.html#zend.config.introduction).
    Applying this change to my WAMP environment fixed the problem… why?
    (please don't say, "Windows is like that!" heeh =) )
    I bet I still have some configuration issue in the local WAMP environment. Still looking.

    Anyway, here is the segment that works in WAMP.
    db->adapter, $config->db->config->asArray());
    Zend_Db_Table::setDefaultAdapter($db);
    ?>

    Thanks

  41. John,

    I wrote the tutorial using my Windows box running Apache 2, so it's not a generic Windows problem. There's no reason why you would have to require Config.php as Config/Ini.php will include it for you.

    Out of interest, are you running APC or something similar on Windows?

    Regards,

    Rob…

  42. OH THANK YOU THANK YOU THANK YOU! it had just what i needed to know about! :)

    – now i only need one thing. How to work with the rewrite router controller from the config file.

  43. Hi,

    Thanks for the tutorial.

    Does $this->_action->getParams() inherently use Zend_Filter_Input ?

    Obviously using the bootstraping principal, my URL will look something like:

    example.com/Foo/Bar/id/45

    Which will give me id=>45 from getParams().

    However, this input still needs to be filtered, new Zend_Filter_Input($_GET) won't give me id=>45 unless I build my URL as:

    example.com/Foo/Bar?id=45.

    Your thoughts would be appreciated.

    Thanks

    Andrew

  44. Andrew,

    As far as I know, getParams() doesn't use Zend_Filter_Input, so you should put it through one of the Zend_Filter methods first.

    Regards,

    Rob…

  45. Thanks that works great, I've got a little internal app coming up in the next month or so, I'm going to use the opportunity to flex the framework a little.

    It all looks very positive, and, with Zend behind it, it's got legs.

    Andrew

  46. I agree with comment #69. I needed to add either of the following two things after .application/models :

    1.) Add a '/' after ./application/models OR

    date_default_timezone_set('AMERICA/NEW YORK');
    set_include_path('.' . PATH_SEPARATOR . './library/'
    . PATH_SEPARATOR . './application/models/'
    . get_include_path());

    2.) Add . PATH_SEPARATOR after './application/models'

    date_default_timezone_set('AMERICA/NEW YORK');
    set_include_path('.' . PATH_SEPARATOR . './library/'
    . PATH_SEPARATOR . './application/models'.PATH_SEPARATOR
    . get_include_path());

    Thank you for the tutorial!

  47. Hi Rob,

    Sorry, I solved that problem by modifying my httpd.conf file to enable mod_rewrite and allow apache to access .htaccess.

    But now, whenever I click "add new album", nothing showes up.

    I only can see "http://mysite/zf-tutorial/index/add" in the address bar of the firefox.

    Thanks.

    Jason.

  48. oh, I read someone else's comments and tried to replace $baseUrl by '/zf-tutorial' and everything works fine now!!!

    Thanks for your great tutorial!!!

    What I did in the index.php are:

    //$router->setRewriteBase($baseUrl);
    $router->setRewriteBase('/zf-tutorial');

    But still, when I type "http://mysite/index.php" and get nothing.

    Jason.

  49. Fatal error: Uncaught exception 'Zend_Db_Adapter_Exception' with message 'The mysql driver is not currently installed' in /usr/local/apache-1.3.36/htdocs/somedomain.com/dev/library/Zend/Db/Adapter/Pdo/Abstract.php:80 Stack trace: #0 /usr/local/apache-1.3.36/htdocs/somedomain.com/dev/library/Zend/Db/Adapter/Abstract.php(146): Zend_Db_Adapter_Pdo_Abstract->_connect() #1 /usr/local/apache-1.3.36/htdocs/somedomain.com/dev/library/Zend/Db/Adapter/Abstract.php(309): Zend_Db_Adapter_Abstract->query('DESCRIBE album', NULL) #2 /usr/local/apache-1.3.36/htdocs/somedomain.com/dev/library/Zend/Db/Adapter/Pdo/Mysql.php(86): Zend_Db_Adapter_Abstract->fetchAll('DESCRIBE album') #3 /usr/local/apache-1.3.36/htdocs/somedomain.com/dev/library/Zend/Db/Table.php(181): Zend_Db_Adapter_Pdo_Mysql->describeTable('album') #4 /usr/local/apache-1.3.36/htdocs/somedomain.com/dev/library/Zend/Db/Table.php(123): Zend_Db_Table->_setup() #5 /usr/local/apache-1.3.36/htdocs/somedomain.com/dev/application/controllers/IndexController.php(15): Zend_Db_Table->__constru in /usr/local/apache-1.3.36/htdocs/somedomain.com/dev/library/Zend/Db/Adapter/Pdo/Abstract.php on line 80

    I have PDO installed

    PDO
    PDO support enabled
    PDO drivers sqlite2
    PHP Extension 20050922

    I am still not able to connect to database. Can u pls help me with this.

    Thnx
    Pooja

  50. Hi Poogja,

    Have you installed the MySQL PDO driver?

    i.e. extension=php_pdo_mysql.dll or extension=php_pdo_mysql.so (depending on system!)

    Regards,

    Rob…

  51. Rob,

    There is no related error message in the apache error log file.

    I have two WAMPs, one is winxp pro sp2+apache 2.0.59+php5.1.6
    when I type index.php there is nothing shows up

    another one is winxp home sp2+apache 1.3.37+php5.1.6
    when I type index.php there is error message shows up as follow

    Fatal error: Uncaught exception 'Zend_Controller_Action_Exception' with message 'IndexController::norouteAction() does not exist and was not trapped in __call().' in c:zf-tutoriallibraryZendControllerAction.php:92 Stack trace: #0 c:zf-tutoriallibraryZendControllerAction.php(114): Zend_Controller_Action->__call('norouteAction', Array) #1 c:zf-tutoriallibraryZendControllerDispatcher.php(185): Zend_Controller_Action->run(Object(Zend_Controller_Dispatcher), Object(Zend_Controller_Dispatcher_Token)) #2 c:zf-tutoriallibraryZendControllerDispatcher.php(136): Zend_Controller_Dispatcher->_dispatch(Object(Zend_Controller_Dispatcher_Token), true) #3 c:zf-tutoriallibraryZendControllerFront.php(254): Zend_Controller_Dispatcher->dispatch(Object(Zend_Controller_Dispatcher_Token)) #4 c:zf-tutorialindex.php(46): Zend_Controller_Front->dispatch() #5 {main} thrown in c:zf-tutoriallibraryZendControllerAction.php on line 92

  52. Rob,

    Sorry, the info in the last post is not clear.

    Today, when I back home, I checked apache 2.0.59's error log, found error message like this (looks like same with apache1.3.37 which shows in the browser)

    [Sat Nov 25 00:01:03 2006] [error] [client 192.168.1.100] PHP Fatal error: Uncaught exception 'Zend_Controller_Action_Exception' with message 'IndexController::norouteAction() does not exist and was not trapped in __call().' in C:\zf-tutorial\library\Zend\Controller\Action.php:92nStack trace:n#0 C:\zf-tutorial\library\Zend\Controller\Action.php(114): Zend_Controller_Action->__call('norouteAction', Array)n#1 C:\zf-tutorial\library\Zend\Controller\Dispatcher.php(185): Zend_Controller_Action->run(Object(Zend_Controller_Dispatcher), Object(Zend_Controller_Dispatcher_Token))n#2 C:\zf-tutorial\library\Zend\Controller\Dispatcher.php(136): Zend_Controller_Dispatcher->_dispatch(Object(Zend_Controller_Dispatcher_Token), true)n#3 C:\zf-tutorial\library\Zend\Controller\Front.php(254): Zend_Controller_Dispatcher->dispatch(Object(Zend_Controller_Dispatcher_Token))n#4 C:\zf-tutorial\index.php(49): Zend_Controller_Front->dispatch()n#5 {main}n thrown in C:\zf-tutorial\library\Zend\Controller\Action.php on line 92

  53. Rob,

    This is the best tutorial I've seen for a long time! It is very clear and everything works first time. Coming from a Java and more recently Ruby on Rails background, I was very frustrated by PHP for the lack of a good MVC framework. The Zend framework has now changed this.

    Thank you for a brilliant introduction to this technology!

    Bruno

  54. Yes, very nice tutorial!

    To exercise the Zend MVC framework, I've
    used the 'chat tutorial' code. They, in turn,
    use a 'library incubator' sub-directory to
    contain ZF code (so that each using app contains
    a private copy of ZF).

    My comment/question is that it would be neat
    if ZF provided a method to make it easy for
    the using-app to retrieve/display the VERSION of
    ZF that is in use (and show a URL-link to where it comes from,etc), so that one coulld easily see
    what version is being used.

    Meanwhile, anyone know WHERE to look in the sub-tree to determine what version of ZF is
    located there?

    TIA…

    Dave

  55. getting error:
    Catchable fatal error: Argument 1 passed to Zend_Controller_Action::__construct() must be an instance of Zend_Controller_Request_Abstract, none given, called in /www/zf-tutorial/application/controllers/IndexController.php on line 6 and defined in /www/zf-tutorial/library/Zend/Controller/Action.php on line 92
    when run index.php

  56. About previous 104. There is no errors in the code. I just by mistake used latest (on that date) frame version that has a few changes that don't work with the example.
    This tutorial is a great work to introduce even experienced programmers to MVC framework. Keep going Rob!

  57. Hello Rob

    i ahve been using ur tutorial as a base for my application

    I m quiete xcited about this

    I have a query .

    i have a controler file called ProjectDetailsControlled.php

    where in the indexAction function

    i have the follwoing code

    $config1 = new Zend_Config_Ini('../application/config.ini', 'general');
    Zend::register('config1', $config1);

    // setup database
    $newdb = Zend_Db::factory($config1->db->adapter, $config1->db->config->asArray());

    $select=new Zend_Db_Select($db);
    $select->from('projectproduct', 'projectproduct.projectproductid');
    $select->from('product', 'product.title as tt');
    $select->from('project','project.projectid');
    $select->where('project.projectid = ?', $id);
    $select->where('projectproduct.projectid = project.projectid');
    $select->where('projectproduct.productid = product.productid');
    //$result = $db->fetchRow($select);
    $result = $db->fetchAll($select);

    $view->result = $result;

    $view->actionTemplate = 'projectDetails.tpl.php';
    echo $view->render('site.tpl.php');

    Now in the projectDetails.tpl.php
    i have this code
    result as $rst) {
    echo $this->escape($rst['tt']);
    }?>

    The above query should return 3 records
    but i m not able to get the code working properly
    Can u pls tell how i can use the data from the above query in my projectDetails.tpl.php file

    Thnx
    Pooja

  58. hey Rob,

    first i wanna thank you for this great tutorial, im totaly new to zend framework and your tutorial was a great help :)

    im using version 0.6.0 of zend framework, i had to make some changes to make it work.. still i have some problems:

    – the edit action wont work, i have a notice "Undefined property: IndexController::$_action…" and an error "Call to a member function getParams() on a non-object in…"

    – another problem is that only firefox can show the page, in IE i get a blank page.

    Thx

  59. Hi Rob,

    The code is still not working, i took the editAction() from your svn version the error i get is the same :
    "Fatal error: Call to a member function getParam() on a non-object in…"
    plus, IE doesnt show anything.

    I guess i have to use earlier version of the framework, but if i had to, what are consequences ? does it have some bugs or security holes ?

  60. Hi Abdou,

    Have you updated your index.php as per the svn version?

    Which line is the "Call to a member function getParam() on a non-object" error happening on?

    Regards,

    Rob…

  61. Hi Rob,

    i just updated my index.php, the difference with yours is the router, i was using one (i wonder why you're not using it :) ), the error is still the same, and its happening on this line:

    "87 $id = (int)$this->_request->getParam('id', 0);"

    I commented the same line, and put a value for $id, ten i had the same error, but this time its about this line:

    "98 $this->_response->setBody($view->render('site.tpl.php'));"

    Error -> "Call to a member function setBody() on a non-object"

    Thx for help.

  62. I have a problem:

    When I do http://localhost/zf/index/add everything is ok. But if I do http://localhost/zf/foo/add is not working (and I have the FooController.php file with the add method). It gives me the 404 error. Even if I define noRouteAction in the IndexController, it gives the same error.

    I have the site in sub-directory zf, and I have the setBaseUrl('/zf') in the controller.

    v0.6

    Can you help me?

    Ricardo

  63. Should one use appendBody() vs setBody() since there could have been other headers, exceptions, etc. written from other parts of the application before hitting this controller?

  64. Will,

    I suspect that it depends on your application as to whether any given controller action is "in charge" of the response enough to use setBody() in preference to appendBody(). Generally, that will depend on if you use plugins or _forward(). (At a guess, anyway!)

    Regards,

    Rob…

  65. Hi Anthony,

    Is your Apache set up correctly to read the .htaccess file? At a guess you haven't got the correct AllowOverride setting in your httpd.conf file.

    Regards,

    Rob…

  66. Fatal error: Class 'Album' not found in C:Program Filesxampphtdocszf-tutorialapplicationcontrollersIndexController.php on line 13
    what would be the solution for this,please help. thanks

  67. I just updated to 0.6 from 0.2 and had a bunch of errors I needed to fix. Mostly changing stuff in the view from if($view->error) to if(isset($view->error)) and so on, but I also needed to change how the router was setup so I came back to your site for the new tutorial and copied the new lines. These lines are:

    $baseUrl = substr($_SERVER['PHP_SELF'], 0, strpos($_SERVER['PHP_SELF'], '/index.php'));
    $frontController = Zend_Controller_Front::getInstance();
    $frontController->setBaseUrl($baseUrl);
    $frontController->setControllerDirectory('../app/controllers');
    $frontController->throwExceptions(true);

    Now though, I can't get any actions in IndexController to work. For example, site.com/test will not go to the action "test" in IndexController, but instead it will error and say that it can't find TestController.php. All I want to do is use noRouteAction in IndexController for a 404 page.

  68. Here's some more info.

    site.com/index goes to the IndexAction in IndexController
    site.com/index/test goes to the TestAction in IndexController
    site.com/index/foobar goes to the noRouteAction in IndexController

    site.com/ goes to the IndexAction in IndexController
    site.com/test says it can't find TestController.php
    site.com/foobar says it can't find FoobarController.php

  69. Hi Kyle,

    The Dispatcher has changed in 0.6 and you need to write a front controller plugin to handle this situation.

    Regards,

    Rob…

  70. Hi Kyle,

    I subscribe to the mailing list and was going to dig through my archives later to see what I could find. Thanks for finding it for me :)

    Regards,

    Rob…

  71. I went with Matt's method to check if the route isDispatchable() which also stops it from erroring if the user tries to execute an action that is a private function. So better all round I think.

  72. A couple questions:

    1) Since there's now init() to automatically execute stuff when a controller is started, is there a similar thing to automatically execute stuff afterwards?

    2) Is there a reason why I shouldn't be using __autoload or is it just not in your tutorial to keep it simple or PHP4 compliant?

    3) When you use the predefined methods to get data from a database, such as findAll(), fetchCol(), etc you get the data back like $table->field, but if you build your own methods with select() you get it back in an array like $table['field']. It's kind of irritating that I get my data in two different formats so is there a way to make these match? I assume it's something to do with Zend_Db_Table_Rowset.

    4) Would you consider doing some mini tutorials about using some basic stuff like cookies, sessions, etc? It took me 20 mins reading the manual to get all the information I needed to use cookies and I still don't know if I'm doing it properly. I could do them the old fashioned way but then I wouldn't be learning anything.

  73. Hi,

    1) postDispatch() or __destruct(). Note that there is a preDispatch() too.

    2) nope – feel free to use __autoload if you want to :)

    3) I agree. Yeah it is to do with Zend_Db_Table_Rowset and is a right pain!

    4) Yeah, mini tutorials will come along when I get some spare time. I'm completely swamped at the moment though :(

    Regards,

    Rob…

  74. So there's no solution to #3? The manual says that you will rarely need to call Zend_Db_Table_Rowset manually. So if it can be called manually then what can we do with it? Can it be used change the data before a model outputs it?

    Thanks for your tutorial though. I've been using it to get every version since 0.1.4 or earlier going. Sure it doesn't go into any depth but it gets you going and then you can google around for more complicated things.

  75. Hi Kyle,

    At the moment, I iterate over the array and turn it into an array of stdClasses with the altered field names as would be used by Zend_Db_Table_Rowset. This is clearly not the right way to do it though!

    Regards,

    Rob…

  76. I am on a shard hosting env. I have the pdo_mysql problem:

    Fatal error: Uncaught exception 'Zend_Db_Adapter_Exception' with message 'The mysql driver is not currently installed' in /home/username/lib/Zend/Db/Adapter/Pdo/Abstract.php:88

    I have the following in my php.ini:

    extension=pdo.so
    extension=mysql.so
    extension=pdo_mysql.so
    magic_quotes_gpc = Off
    register_globals = off

  77. Oh, I forgot, here is the phpinfo() output:

    './configure' '–with-xml' '–enable-bcmath' '–enable-calendar' '–with-curl' '–with-dom' '–with-dom-xslt' '–with-dom-exslt' '–enable-exif' '–enable-ftp' '–with-gd' '–with-jpeg-dir=/usr/local' '–with-png-dir=/usr' '–with-xpm-dir=/usr/X11R6' '–with-gettext' '–with-imap=/usr/local/imap-2004g' '–enable-mbstring' '–enable-mbstr-enc-trans' '–enable-mbregex' '–with-mcrypt' '–enable-memory-limit' '–with-mhash' '–enable-magic-quotes' '–with-mysqli' '–with-mysql=/usr' '–with-openssl' '–enable-discard-path' '–with-pear' '–enable-xslt' '–with-xslt-sablot' '–enable-sockets' '–enable-track-vars' '–with-ttf' '–with-freetype-dir=/usr' '–enable-gd-native-ttf' '–enable-versioning' '–enable-wddx' '–with-xmlrpc' '–with-zlib' '–prefix=/usr/local/php5' '–exec-prefix=/usr/local/php5' '–program-suffix=5' '–enable-force-cgi-redirect' '–enable-discard-path'

  78. Hi Mike,

    The problem is that your host has not enabled the PDO extension. You could try using the Zend_Db adapater for mysqli which is in the incubator.

    Regards,

    Rob…

  79. hi, thanks for the tutorial! – i was just wondering if there are a way to select from more tables. Lets say i have a table called albums, and one called artists. I have a modeler for both tables and i can select from both individual…

    But what i cant do is select from both at the same time like this,

    $albums = new album();
    $albums->fetchAll();
    $artists = new artist();
    $artists->fetchAll();

    – so lets say i want data from both i'll have to do it manual by using the database object and the select function

  80. wops, pushed before i was done writing :)

    but i was wondering if there are a way to get by this with the use of the modeler? i've been looking around and cant seem to find a solution to this. It seems like the pdo CAN do query's simultaneity but i dont know if the zend framework has the same features. I cant seem to find anything about it in the manual

  81. i've been playing with this demo, on a windows box and linux. windows box path creation is messed up using the wrong slashes assuming linux. and then linux path creation is not working either.

    great framework

  82. Ranza,

    You need a class that implements the ActiveRecord design pattern. Zend_Db_Table doesn't do this, so you either need to roll your own or work around it until something is added to the Zend Framework.

    As far as I remember, Bill Karwin is looking at the database components in the 0.8 time frame.

    Regards,

    Rob…

  83. Jim,

    What do you mean by "Windows box path creation is messed up"? The tutorial specifically uses the PATH_SEPARATOR constant to ensure that it does work.

    If you mean directory separator, then PHP on Windows can understand that / is a directory separator just like is.

    Regards,

    Rob…

  84. Hi Rob,

    problem at page 6 :
    I changed the .htaccess in C:ProgrammiApache Software FoundationApache2.2htdocs ( document root) this way:

    RewriteEngine on
    RewriteBase /zf_tutorial
    RewriteRule !.(js|ico|txt|gif|jpg|png|css)$ index.php
    php_flag magic_quotes_gpc off

    When I type http://localhost/ I can see the right page.
    When I type http://localhost/index/ I can see the right page.

    When I type http://localhost/index/add I see always " in IndexController::IndexAction()";

    It seems that (apache /ZF ) redirect to defalt index action.

    what the problem ?
    thanks giorgio

  85. Hi,
    After i copied 'Zend' folder and Zend.php to zf-tutoriallibrary
    tutorial is working fine :-)

    thanks
    San.

  86. Hi Rob!

    I would like to extend the application and make a view page to each album.

    Offcource i use viewAction() and i make something like

    function viewAction() {
    $view =Zend::registry('view');
    $view->title = "view the doc";

    $doc = new Doc(); //i have change that,it's ok do not confuced
    $view->docs = $doc->fetchAll();

    $view->actionTemplate='indexView.tpl.php';
    $this->_response->setBody($view->render('site.tpl.php'));
    }

    and in the indexView.tpl.php i use
    escape($this->doc->name);?>

    byt it looks like that is not so simple and i take Notice: Undefined property: Zend_View::$doc in …

    Can you help me a while?

    thanks!

  87. hi Rob,

    I've been trying to use your tutorial and try to run it but why I always got this error :

    Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception' with message '"index.php" controller does not exist' in D:projectoprekzendlibraryZend.php:229 Stack trace: #0 D:projectoprekzendlibraryZendControllerDispatcher.php(386): Zend::exception('Zend_Controller…', '"index.php" con…') #1 D:projectoprekzendlibraryZendControllerFront.php(725): Zend_Controller_Dispatcher->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #2 D:projectoprekzendindex.php(16): Zend_Controller_Front->dispatch() #3 {main} thrown in D:projectoprekzendlibraryZend.php on line 229

    I'm using W2K with IIS and PHP 5.1.4

    thanks..

  88. Bagus,

    I think that the base url is not being set to the correct value.

    Try adding:
    $frontController->setBaseUrl('/oprekzend');

    After:
    $frontController->throwExceptions(true);

    in index.php.

    Regards,

    Rob…

  89. Hi,
    First I would like to thank you for this great tutorial, may be the next step would be to include smarty and Ajax.
    Second, when I tried calling http://www.mysite.com/zend/index.php, I got an error IndexPHPControllerPHP not found. So I investigated the root cause and traced it in the dispatcher, what I did was adding this line:
    $frontController->getDispatcher()->setWordDelimiter('.php');
    before
    $frontController->throwExceptions(true);

    I am wondering if this is safe to do that in Framework 0.7. By the way the fix to this same problem mentioned in here http://framework.zend.com/issues/browse/ZF-835 didn't work for me.

    -Ali

  90. I ran into this very weird error. When i deploy the website on my production server i get this error as if it looks for my index controller in some weird dir.

    ive tryed to set a basedir, give it absolute urls to the folders and so on. Do you have any idear of what causes this error?

    error:

    Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception' with message '"index" controller does not exist' in /home/frontier/library/Zend.php:229 Stack trace: #0 /home/frontier/library/Zend/Controller/Dispatcher.php(386): Zend::exception('Zend_Controller…', '"index" control…') #1 /home/frontier/library/Zend/Controller/Front.php(725): Zend_Controller_Dispatcher->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #2 /home/frontier/public_html/index.php(43): Zend_Controller_Front->dispatch() #3 {main} thrown in /home/frontier/library/Zend.php on line 229

    my index.php: http://pastebin.dk/index.php?show=3054

  91. ok, for ZF 0.8 :
    (It's not a bug, it's a feature)! Zend_Controller_RewriteRouter was renamed to Zend_Controller_Router_Rewrite.

  92. ah i found the problem. the controller looks for IndexController.php, not indexController.php :) – i coded the thing on my macbook and apache isnt case sensitive. My production server is a linux which IS case sensitive :)

    kinda bad mistake sorry!

  93. Just went through the tutorial, very clear. Thanks.

    Unfortunately I downloaded a nightly snapshot rather than 0.8 and the Zend_Filter_Input class has been deprecated (and removed from the source tree) eight days ago.

    I cannot find any documentation on how the replacement solution should be implemented, but thought you should know. If you find anything, I'd appreciate a response too!

    Thanks

    Alan

  94. Alan,

    You can use $_POST directly in the action functions and remove all reference to Zend_Filter_Input in the index.php.

    Have a look at Zend_Validate to do the validation bits. It's not static, so you have to create an instance of the Zend_Validate_XXX class first and then call it's check() method.

    Hope that gives you some pointers.

    Regards,

    Rob…

  95. 0.9.0 has affected the tutorial as components are deprecated. So far Zend::loadClass (index.php lines 10-15)
    Zend_Filter_Input (index.php line 15)
    Zend::register (index.php lines 18-19).

    I keep referring back to this tutorial because it work so well. Thanks for keeping up with it.

  96. Look up just above your comments to #176, guys. He is working on a 0.9.0 version and it will be out shortly.

  97. Hi, I downloaded version 0.8.0 and at the IndexAdd action, the follow error occurs:

    Fatal error: Uncaught exception 'Zend_Controller_Response_Exception' with message 'Cannot send headers; headers already sent' in D:wwwprojetolibZendControllerResponseAbstract.php:240 Stack trace: #0 D:wwwprojetolibZendControllerResponseAbstract.php(125): Zend_Controller_Response_Abstract->canSendHeaders(true) #1 D:wwwprojetolibZendControllerAction.php(607): Zend_Controller_Response_Abstract->setRedirect('/projeto/', 302) #2 D:wwwprojetoapplicationcontrollersIndexController.php(45): Zend_Controller_Action->_redirect('/') #3 D:wwwprojetolibZendControllerAction.php(392): IndexController->addAction() #4 D:wwwprojetolibZendControllerDispatcherStandard.php(211): Zend_Controller_Action->dispatch('addAction') #5 D:wwwprojetolibZendControllerFront.php(750): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #6 D:wwwprojetoindex.php(44): Zend_Controller_Front->dispatch() #7 {main} thrown in D:wwwprojetolibZendControllerResponseAbstract.php on line 240

    I think its because line "$this->_redirect('/');" but I don´t know how to fix it…

  98. I was getting the error:
    Uncaught exception 'Zend_View_Exception' with message 'script 'index/index.phtml' not found in path' in /Volumes/Storage/SYSTEM/wwwroot/zend/library/Zend/View/Abstract.php:594

    until I changed the line
    $view->setScriptPath(realpath('./application/views'));

    to

    $view->setScriptPath(realpath('./application/views/scripts'));

    when trying to use your 26th revision in your zf-tutoiral with zend framework 0.9.0 … should I not had to have done this?

  99. Scott,

    It's a bug in revision 26. We don't need to create the view in the bootstrap any more. Revision 27 fixes it.

    Regards,

    Rob…

  100. Can't download rev27 or perhaps don't know how to use svn.
    I'm having a lot of problems with include path. I had to set up a separate path file to require_once each class file, for some reason I can't include the entire dir. Also having the same problem with Abstract.php (post 182), but I don't know how to fix (adding 'scripts' didn't work).

  101. Rob,

    Thanks for the response, I checked out Rev 27 and that worked without modification…actually, that is not true. I had the same problem as Matt in setting the include path…I used his include_path that he showed in post 69 (I am running a MAMP setup in OSX, just so you know). This is a great tutorial and trying to fix bugs is what makes me understand the framework that much better, thanks for your hard work!

  102. Just downloaded version 1.3.0
    After adjusting pathing to match my need to store things outside the root, it works perfectly. Took all of 10 minutes.

    Now to see if I can break (err) use it again as a study guide. :-)

    Once more… Thanks loads.

  103. At first I couldn't get the delete functionality to work. Already thought it was strange the tutorial referred to a zf-tutorial/application/views/indexDelete.tpl.phpp template, which doesn't seem to fit in with the rest of the structure.

    It worked as soon as I applied the changes in the delete template that was made before, located at zf-tutorial/application/views/scripts/index/delete.phtml.

  104. I too am getting the same error as Jose #180 – I too think it has something to do with the $this->_redirect('/');

    Can't send headers error.

    Looking forward to a solution.

  105. Jeff,

    Headers already sent issues are usually related to echoing out something before the call to _redirect().

    Out of interest, do you have a closing ?> followed by a couple of blank lines anywhere?

    Regards,

    Rob…

  106. Hi Rob

    Thanks for getting back to me so quickly – no, no closing ?> and no blank lines anywhere.

    It just stops at the redirect, I can echo something out right before but not before the 'return;'

    I've copied the code below:

    Cheers
    Jeff

    public function editusersAction()
    {
    $this->view->pageTitle = 'edit this users';
    $this->view->section = ";
    $this->view->setCSS = ";
    $this->view->action = 'edit';
    $this->view->button = 'update';
    $this->view->userTypeLabel = 'you are a';
    $this->view->users = new stdClass();

    $db = Zend_Registry::get('dbAdapter');
    // set up null values
    $id = $this->getRequest()->getParam('id');
    $sql = $db->select();
    $sql->from('users', '*');
    $sql->where('users.id =?', $id);
    $this->view->users = $db->fetchRow($sql);

    $userTypeSql = $db->select();
    $userTypeSql->from('user_types', '*');
    $this->view->userTypes = $db->fetchAll($userTypeSql);

    if ($this->getRequest()->isPost()) {
    Zend_Loader::loadClass('Zend_Filter_StripTags');
    $filter = new Zend_Filter_StripTags();
    // set the post variables
    $now = date('Y-m-d H:i:s');
    $id = (int)$this->_request->getPost('id');
    $user_type_id = trim($filter->filter($this->_request->getPost('user_type_id')));
    $username = trim($filter->filter($this->_request->getPost('username')));
    $password = trim($filter->filter($this->_request->getPost('password')));
    $email = trim($filter->filter($this->_request->getPost('email')));
    $verified = trim($filter->filter($this->_request->getPost('verified')));
    $last_updated = $now;
    $deleted = trim($filter->filter($this->_request->getPost('deleted')));
    $preferred_name = trim($filter->filter($this->_request->getPost('preferred_name')));

    $data = array(
    'user_type_id'=>$user_type_id,
    'username'=>$username,
    'password'=>$password,
    'email'=>$email,
    'verified'=>$verified,
    'last_updated'=>$now,
    'deleted'=>$deleted,
    'preferred_name'=>$preferred_name,
    );
    $table = 'users';
    $where = $db->quoteInto('id = ?', $id);
    $db->update($table, $data, $where);
    $this->_redirect('/');
    return;
    }
    $this->render();
    }

  107. Hi Rob

    just to add aomething else to the mix – it happens on the delete as well, and there's nothing in that one at all.

    public function deleteusersAction()
    {
    $db = Zend_Registry::get('dbAdapter');
    $id = $this->getRequest()->getParam('id');
    $table = 'users';
    $where = $db->quoteInto('id = ?', $id);
    $rows_affected = $db->delete($table, $where);
    $this->_redirect('/');
    }

    am I totally missing something?

    Jeff

  108. Thanks for tutorial and to all who are posting solutions to various problems, it's been very helpful.
    in resolving the include issue, and conroller issues. I am now working wih tutorial v1.3.1 and ZF v0.9.1 and have run into a problem with the view template pages (.phtml). When I send the controller request it goes to the view template (add.phtml, etc.), but doesn't parse the php. Any suggestions?

  109. Jeff,

    It's almost certainly in another file, or at the top of the controller file.

    Do you have the same problem with the zip file download?

    Regards,

    Rob…

  110. Rob,
    Thanks for the reply. I added
    AddType application/x-httpd-php .php .php3 .phtml

    to my httpd.conf, but same result: Page is blank; view source: html is visible, php is not visible on source or on browser display (perhaps the fact that it is not visible in source means it is being parsed, just not correctly).

  111. Hi Rob

    Just to let you know – I found the problem, it was 1 extra line of space before my opening

  112. Rob,
    A little syntax error was the culprit, thanks for the assistance.

    This may not be the best place, but does anyone know the status of the forum? I registered, but account hasn't been activated and I don't get any responses from admins.

    Keep up the great work it is much appreciated!

  113. Thanks for the tutorial, it has been extremely useful!

    One thing I could have used though is some more info about avoiding SQL injection. For instance on page 16 you cast the getPost('id') as an int thus making it safe, but because of that you didn't use something like $table->getAdapter()->quoteInto('id = ?', $id) which, for me, would have been more helpful.

    From what I can tell you don't need to worry about escaping data that you insert using methods like $table->insert($data), but you do need to worry about escaping data used in the 'where' clause which is where quoteInto comes into play. Before using the Zend Framework I used Mysqli with prepared statements so I am a bit paranoid about becoming vulnerable to them again. ;)

  114. John,

    You shouldn't use quote into for Integer database fields as it's incorrect SQL and many database engines will disallow it. That's why I used the cast to int.

    As you've noticed, insert()/update() automatically quote, but the where clause doesn't. It's just one of those things you have to learn as far as I can see.

    Having said that, if you pass in an array as the $where, it will quote. e.g:
    $r = $table->fetchAll(array('date > ?', '2002-02-02'))

    Regards,

    Rob…

  115. Thanks for the reply,

    I'll look into passing the where clause as an array, it looks useful.

    As far as I can tell it is safe to pass quoteInto() an int as it tests if it is an int before quoting (Zend_Db_Adapter_Abstract, line 440). I don't want to imply that casting the id as an int is a bad thing to do, it just would have helped me personally to have it explained. :)

    Cheers,
    John

  116. Hello Rob,
    thank you for the great tutorial!

    I have a problem with the example application – cd collection.

    The index list is displayed correctly. When I click at the "Edit" link, the form is populated with the artist name and title. Well, when I press the "Update" button, I got an error message at the both input fields:

    Notice: Trying to get property of non-object in C:Program Filesxampphtdocszf-tutorialapplicationviewsscriptsindex_form.phtml on line 5

    Notice: Trying to get property of non-object in C:Program Filesxampphtdocszf-tutorialapplicationviewsscriptsindex_form.phtml on line 10

    Also, when I try to delete a record and press the "Yes" button, the record is not deleted!

    When I try to add a new album, nothing happends – the form just reload.

    It seems that

    $this->_request->getPost('artist')

    return an empty value.

  117. Actualy it seems to have a problem with "localhost". When I try to load the website via localhost/zf-tutorial it does not works correctly. When I try to access via real ip address, even via 127.0.0.1 – it works!

  118. Just hoping for a bit of help. With the current stable beta (0.9.2) and tutorial 1.3.3, having only done all the .htaccess files and index.php, I get:

    [08-Apr-2007 10:34:33] PHP Fatal error: Cannot access protected property Zend_Controller_Front::$_instance in /Applications/MAMP/htdocs/zf-tutorial/library/Zend/Controller/Front.php on line 147

    If I use the current snapshot instead, it works as expected (complaining about 'Invalid controller specified (index)'). But then when I go and make application/controllers/IndexController.php, it goes back to the same message as before,

    PHP Fatal error: Cannot access protected property Zend_Controller_Front::$_instance in /Applications/MAMP/htdocs/zf-tutorial/library/Zend/Controller/Front.php on line 147

    I don't get a stack trace to work with either.

    Any suggestions?

    php 5.2.0
    Apache 2.0.59

  119. Never mind… found out "MAMP" (Mac AMP package) had eAccelerator and Zend Optimizer running by default. Killed them and it's all good.

    Thanks for the great tutorial.

  120. Thank you for your great tutorial!

    I have a short question: I'm a little bit unsure about the right syntax. Your class "Album" extends from "Zend_Db_Table", but the Reference Manual from Zend extends from "Zend_Db_Table_Abstract". Is there a difference? If not, what is the recommended way?

  121. Found the answer by myself:
    Using of Zend_Db_Table is deprecated since V 0.9 of the Zend Framework. The Reference Manual from Zend is correct. I will use Zend_Db_Table_Abstract in my projects.

  122. Why don't you use
    require_once 'Zend/Loader.php';
    Zend_Loader::registerAutoload();

    It is far easier then using
    Zend_Loader::loadClass('Zend_Controller_Front');
    Zend_Loader::loadClass('Zend_Registry');
    Zend_Loader::loadClass('Zend_View');

  123. I had som problems with the .htaccess file. I got internal servererrors, or got redirected to wrong directorys. The following worked for me:

    RewriteEngine On
    RewriteRule ^.+$ /zf-tutorial/

  124. Remi,

    As you've noticed, Zend_Db_Table_Abstract is the correct way to do it. My use of Zend_Db_Table is an oversight when I updated to the new ways of doing things.

    Regards,

    Rob…

  125. Matt,

    It saved having to explain autoload :)

    Guy,
    Your Apache isn't reading your .htaccess file. Ensure that you have AllowOveride All set in your httpd.conf.

    Regards,

    Rob…

  126. Hallo Rob, I try to inisalize een class but it dont work:
    $shippingmethods = new ShippingmethodsController();
    $shippingmethods->indexAction

    —————–

        function indexAction()
        {
            if (strtolower($_SERVER['REQUEST_METHOD']) == 'post') {
                Zend_Loader::loadClass('Zend_Filter_StripTags');
                $filter = new Zend_Filter_StripTags();
                //$post = Zend::registry('post');
                 $_SESSION['shippingmethodid'] = trim($filter->filter($this->_request->getPost('shippingmethod')));
    	 					 $this->view->shippingmethodid = $_SESSION['shippingmethodid'];
          	}
          	if (!empty ($_SESSION['shippingmethodid'])){$this->view->shippingmethodid = $_SESSION['shippingmethodid'];}
          
          	//$this->view->cartactionTemplate = 'showBigCartIndex.tpl.php';
          	//$this->render();
    
          
          	$shippingmethods = new ShippingmethodsController();
            $shippingmethods->indexAction();
          	$this->loadCartAction();
    
          	$this->render();
    
        }
    

    —————-
    thanks

  127. hai rob, i want to initialize ShippingmethodsController() within
    CartController but i get this error :
    Fatal error: Argument 1 passed to Zend_Controller_Action::__construct() must be an object of class Zend_Controller_Request_Abstract, called in
    ==============
    initView();
    $this->view->baseUrl = $this->_request->getBaseUrl();
    }
    function indexAction()
    {
    $shippingmethods = new ShippingmethodsController();
    $shippingmethods->indexAction();
    $this->render();

    }
    }

  128. thanks for your hulp

    this is the ShippingmethodsController
    =================

    initView();
    Zend_Loader::loadClass('Shippingmethods');
    $this->view->baseUrl = $this->_request->getBaseUrl();

    }

    function indexAction()
    {
    $Shippingmethods = new Shippingmethods();
    $order = 'shippingname';
    $rowset = $Shippingmethods->fetchAll(null, $order);
    $this->view->Shippingmethods = $rowset;
    }

    }

  129. thanks Rob,
    Yes
    =============
    initView();
    Zend_Loader::loadClass('Shippingmethods');
    $this->view->baseUrl = $this->_request->getBaseUrl();
    }

    function indexAction()
    {
    $Shippingmethods = new Shippingmethods();
    $order = 'shippingname';
    $rowset = $Shippingmethods->fetchAll(null, $order);
    $this->view->Shippingmethods = $rowset;
    }

    }

  130. Hi Rob,

    Firstly, I'd like to thank you for your hard work putting this comprehensive tutorial together. It's easily the best one I've read, and I've been looking for the "right way" to use the framework for a while.

    I'm tryin to use your example with a SQLITE2 database. I've created a sqlite2 database called zftest.db, and the config file now looks like this:

    [general]
    db.adapter = PDO_SQLITE
    db.config.dbname = zftest.db
    db.config.sqlite2 = TRUE

    I'm not sure where the actual database file should go in the structure, so I've put it in every folder to test, but no joy :(

    Could you help with this please?

  131. Rushy2uk,

    I'd guess that it needs to be in the root directory. Alternatively, I'd try a fully qualified path as the dbname field.

    Regards,

    Rob…

  132. Thanks Rob, I'll try again later.
    I also read it's possible to use the mysqli adapter with Zend_Db, put I can't find any information on this.

    Can you point me in the right direction please? (I'm keen to finish your tutorial, but my host doesn't support PDO_MYSQL, only PDO_SQLITE and MySQLi)

  133. No joy this evening with the PDO_SQLITE or MySQLi.

    Has anyone managed to get those adapters working with your tutorial?

  134. I stayed up until 01:00 last night, and managed to get your tutorial working with the MYSQLI adapter (Zend_Db), but still couldn't get SQLITE working.

    In the ZF manual, it says I should use the "dbname" and "dsnprefix" PDO options like this:

    [general]
    db.adapter = PDO_SQLITE
    db.config.dbname = zftest.sq2
    db.config.dsnprefix = sqlite2

    I'd really like to get your tutorial working with SQLite too, but a blank screen is displayed when I use the above .ini file.

    Could you verify that it's possible to use SQLite with your tutorial please? (so I don't go insane!)

    Thanks again for teaching me the "right way" of using the ZF.

  135. Hi Rushy2uk,

    I'm a little snowed under with day-job work at the moment, but when I get some free time, I'll have a look at SQLite.

    Regards,

    Rob…

  136. Great tutorial! Thanks so much for producing it.
    I'm trying out variations of things with your tutorial. One area I have a problem is when trying to do a distinct select in Zend_Db_Table. The manual shows how to do it with Zend_Db_Select but how would I do it using Zend_Db_Table?

  137. I have tried to adapt your tutorial to build a news site. I wish to add a "readon" to each news "intro" on the frontpage. That requires controller/view code to render one row only. I have tried to extend your controller/view code, but the view does not render. I feel that "foreach" must be ditched in favour of "for" in the view file.Cannot write the correct code. Any suggestions?

  138. Hai Rob, wat is the Zend_Auth namespace, and How can i acces to its data. is it 'Zend_Auth'. can i do so: $authSpaceAccessor1 = new Zend_Session_Namespace('Zend_Auth');

  139. Hai Rob, can i place this in my Bootstrap file I want to acces session data in all controllers
    =============== $user = Zend_Auth::getInstance()->getIdentity();
    echo $user->customerslastname;

  140. nour,

    No idea bout what namespace Zend_Auth uses.

    You could certainly place your getIdentity call in the bootstrap though.

    Regards,

    Rob…

  141. i'm following this tutorial for the first time, and i'm running apache2.2 in a windows box. i, have made one simple change to what the tutorial says, instead of using a subfolder in the root called zf-tutorial, i used a subfolder called "prazer", i think this is not a big dial, anyway i came to a little problem at page 6, if i use the URL http://localhost/prazer/ it shows me "in IndexController::indexAction()" as it should but if i add the "index/add" to the URL like this "http://localhost/prazer/index/add" it gives me an 404 error it seems like the URI component is not doing what it should be. Did i missconfigured something? what can be the problem in this case?

  142. Rob, Thank problem solved.
    I have changed that but just on "
    Options FollowSymLinks
    AllowOverride All …" forgot to check for more… Beginners misstake.
    This kind of things are new to me is the first time i set up a server by hand, till now i have been using server packs like Wamp or Xampp. Many thanks.

  143. When I run the code on page 3 in your tutorial, I get this:

    Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception' with message 'Invalid controller specified (index)' in C:Apachehtdocszf-tutoriallibraryZendControllerDispatcherStandard.php:173 Stack trace: #0 C:Apachehtdocszf-tutoriallibraryZendControllerFront.php(753): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #1 C:Apachehtdocszf-tutorialindex.php(15): Zend_Controller_Front->dispatch() #2 {main} thrown in C:Apachehtdocszf-tutoriallibraryZendControllerDispatcherStandard.php on line 173

  144. Rushy2uk,

    I was able to do the tutorial using SQLite with the following config.ini:

    [general]
    db.adapter = PDO_SQLITE
    db.config.host = localhost
    db.config.username = zftut
    db.config.password = zftut
    db.config.dbname = library/zftutorial.sqlite

    And the zftutorial.sqlite file is in just in my library dir. What specific error do you see?

    Also, for everyone, I wrote up my own tutorial on adding unit-tests to ZF controllers, if anyone is interested.

    http://tulsaphp.net/?q=node/40

  145. Luke,

    What version of SQLite did you get working?

    It looks like you're using SQLite 3.
    I have to get it working on SQLite 2.
    Have you managed that too?

    Also, I thought you didn't need a username and password with SQLite?

    Rushy

  146. I got stuck on page six for half a day until I realised apache was ignoring .htaccess files. I had to change AlloverrideAll in httpd.conf before I had any luck.

    Can I suggest putting a note in the tut to check that .htaccess is working.

    Cheers,

  147. Sorry, typo above. Should be: AllowOverride All.

    I'm also stuck on pg 14 with the SQLite issue: I only have sqlite2 and sqlite pdo drivers.

    I've got an XAMPP setup on mac 10.4 and can't work out how to install PDO_mysql?

    Are there any simple instructions to do this? They would be very much appreciated.

    Cheers,

  148. For those that are using WAMP5, you may encounter an error when testing the architecture out for the first time. I tried manually changing the php.ini to include the php_pdo_mysql.dll extension, but it didn't work. Its absence can be fixed via the WAMP icon in the system tray.

    Left-click the icon, go to PHP Extensions, and select php_pdo_mysql, then open the menu up again and Refresh it. It should be there, and your localhost/zf-tutorial will display correctly.

  149. Hi prebugged..
    I had same prob. In wamp there is 2 php.ini files.
    wampApache2binphp.ini and
    wampphpphp.ini
    you have make the changes in
    apache2binphp.ini
    Regards.

  150. Thank you for an excellent tutorial.

    I have most of it up and running in an afternoon even though I am totally new to the Zend Framework.

    Thumbs up!

    Stig

  151. Hi Rob. I am glad I said most of it and not all. The edit and delete I can not get to work. Adding albums works fine.

    Details: WinXP with Apache Server 2.2.4 on port 8080. Zend Framework 0.9.3 beta. Php version 5.2.2.2. MySql version 5.0.

    When pressing edit from index.php, I get somewhat the same error as in #206. The first text field displays:

    Notice: Trying to get property of non-object in C:Program FilesApache Software FoundationApache2.2htdocszf-tutorialapplicationviewsscriptsIndex_form.phtml on line 5.

    In text field 2 the message is the same but with the line number 10.

    The code at line 5:

    escape(trim($this->album->artist));?>"/>

    The error message is displayed along with b and br tags.

    When clicking the delete link all that happens is that the page is refreshed and nothing deleted.

    I use the code from your revision 48, stage 2.

    Do you have any idea what causes this?

    Regards,

    Stig

    PS. In #176 you write "…after you fix the typo in Zend/Db/Table/Row/Abstract.php".

    What is the typo?

  152. Ups! Somehow you did not get all the code at: The code at line 5, but the code is identical to yours in _form.phtml.

    Stig

  153. Ups again: I found the answer to my PS question in one of your earlier posts. Thanks. It is fixed in the 0.9.3 version.

  154. Hi Rob,
    I found out what the problem is. It is located 10 inches in front of screen :)

    In your index.phtml, you have a slash after id in the edit and delete parameters. I didn't. Adding the slash solved the problem.

    Amazing. Thank you, man!

  155. I'm facing a problem where localhost/zf_test/index/index/ and localhost/zf_test/index/test/ works, but localhost/zf_test/test/index/ and localhost/zf_test/test/test/ generates 404 File Not Found error.

    I'm using ZF 0.9.3 beta on Windows XP with Apache

    The following is my .htaccess content:
    RewriteEngine on

    RewriteOptions Inherit
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule (.*) index.php?apache_path=$1 [L,QSA]

    and my index.php is

    setBaseUrl( "/axchange/" );
    $frontController->run('./controllers');

    I have

    IndexController.php and TestController.php in my ./controllers folder

    Can anybody help me to solve this prob.

    Thanks in advance

  156. Sorry, my index.php content is

    Zend_Loader::loadClass( "Zend_Controller_Front" );

    $frontController = Zend_Controller_Front::getInstance();
    $frontController->setBaseUrl( "/zf_test/" );
    $frontController->run('./controllers');

    if I use _forward("index", "test" ) inside the IndexController.php, it will call the TestController.php functions. But not directly from the url test/index/ calling.

  157. Hi Rob

    Since I find the quality of your work excellent I would like to make a Danish translation. How to proceed?

    Best regards,
    Stig

  158. Hi Rob,

    I had un-commented the following 2 lines in my httpd.conf

    LoadModule rewrite_module modules/mod_rewrite.so
    AddModule mod_rewrite.c

    Is there somethings else I need to do to enable the mod_rewrite? Previously they are commented. Is there other way to detech whether the .htaccess is being used?

    Thanks Rob

  159. Hi Rob,

    Is there a way to catch exceptions for non existing urls?

    If I i.e. try to access a non existing folder, say scripts, from the browser address line, I get this error message: Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception' with message 'Invalid controller specified (scripts)

    Would it be possible to re-route to index.php when an invalid url is received?

    Thanks, Stig.

  160. Hi Rob,

    I found the answer. It has to do with me setting the base url. I have to set it as "http://localhost/sitename"

    then a faulty url is redirected to index.phtml

    Stig

  161. Great tutorial Rob, I am new to PHP and Zend. Just tried with your tutorial and it is very interesting.
    Sample application is up and running.
    Thanks.

  162. Hi Rob,

    Finally I had figured out the .htaccess is not being used even when I enabled the mod_rewrite

    I find out that the httpd.conf defaulted to

    Options FollowSymLinks
    AllowOverride None

    which disregard all the .htaccess to be used. So I changed it to

    Options FollowSymLinks
    AllowOverride All

    and the Zend_Control magic works.

    Thanks for pointing me to the right direction.

  163. Great tutorial!

    Small spelling mistake on page 5 (version 1.3.4) … it's "Organizing", not "Organising".

  164. Thanks for continuing this excellent tutorial. I've currently got a system with a number of different actions, each action works with the same type of data and as a result, the view needed is always the same. I currently have 8 different views, which all are exactly the same. Is there a simple way to define the view that should be used for an action? This way I could define one view to be used with my actions. I realise I could create one file and then 8 views which reference the one (like you do with header and footer) but it would be easier if I could loose the files altogether.

    Thanks

    Andrew

  165. Yes. I need to update the tutorial to handle the new ViewRenderer action helper.

    Just need to find some time!

    Regards,

    Rob…

  166. Hi Rob

    My code for trying to retain the tag does not work.

    Zend_Loader::loadClass('Zend_Filter_StripTags');
    $filter = new Zend_Filter_StripTags();
    $tagsAllowed = 'p';//or"
    $this->setTagsAllowed($tagsAllowed);

    Any suggestions?

  167. Getting this error with the tutorial (v1.3.4):

    Zend_View_Exception: helper 'escape_string' not found in path in C:Program Filesxampphtdocszf_tutoriallibraryZendViewAbstract.php on line 1000

    Up to this point in the tutorial (page 7 "Setting up the View"), everything was fine.

    Using ZF RC 1.0 with xampp 5.2, php 5.2

  168. Jordan,

    I take it back – that error is something else. You should have
    $this->escape()
    not
    $this->escape_string()
    in your .phtml files.

    Regards,

    Rob…

  169. Rob, thanks for not only writing a tutorial, but more importantly keeping it up to date as the Framework changes throughout time.

    It's the only one I've come across that's got me sufficiently started – I just need to look at authentication/session stuff and I'll be sorted :) All the others I've have found have been 0.1.x – not good!!!!

    Keep up the fantastic work and thanks again :)

    C

    PS – RE post 279, I disagree but I'm english ;-)

  170. Great Tutorial!!! thanks a lot..
    In the tutorial(1.4.0) you forget to load in index.php

    Zend_Loader::loadClass('Zend_Debug');
    Zend_Loader::loadClass('Zend_View');

    Put it in the next version…

    sorry but my english is very poor.
    regards

  171. Hello Rob!
    Great job!
    I'm using it for homework :p

    I'v got a problem when trying to go to "http://localhost/zf-tutorial/" : error 500 !
    but when going to "http://localhost/zf-tutorial/index" : normal index page of my website :(

    The other pages seem to be ok…

    Any idea ?

  172. If it helps, the errlog message is : "Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary."
    The owner of the server says that it doesn't like "RewriteRule .* index.php" >_

  173. to go far away in my investigation, I tried "http://localhost/zf-tutorial/index.php”

    So I think that if the rewrite rule had worked well, there would be no problem… it would have redirected me at index.php an so to the IndexControler/IndexAction page…

    help :'(

  174. A friend of mine helped me. I just had to modify jte rewrite rule .htaccess :

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .* index.php [L]

    php_flag magic_quotes_gpc off
    php_flag register_globals off

    It works now, but I absolutely don't understand why …

  175. I'm afraid I didn't, actually !!!
    I tried to create other controllers in the same directory that IndexController.php, but I can't call their actions… Same server error 500…

    Does somebody have an idea ?

  176. My error log says :
    Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary.

  177. ->I accidently posted this under the Zend_Auth tutorial by accident. I will surely help out better here.
    Just posting to help out some would be users of the “Getting Started With Zend Framework – Tutorial”. On page 12 zf-tutorial/index.php will have to read: $db = Zend_Db::factory($config->db->adapter,
    $config->db->config->toArray()); instead of $db = Zend_Db::factory($config->db->adapter,
    $config->db->config->asArray()); in order to be used with ZF-RC2. Just a friendly reminder.

    Your tutorials are great. I would hate to see someone new to the framework give up because of something so small. Keep up the good work.

  178. I'm actually thinking about giving up… I have to finish my homework before tonight… just few hours to solve my problem and finish my homework.. I'm afraid I can't…

  179. Thanks for an excllent tutorial.

    I believe that:

    $this->view->baseUrl =
    $this->_request->getBaseUrl();

    in the init-method of the IndexController should be:

    $this->view->baseUrl =
    dirname($this->_request->getBaseUrl());

    Regards
    Allan

  180. Hi again.
    I'm sorry, my previous post was wrong – the "dirname()" part, not the "excellent tutorial part :)

    Regards
    Allan

  181. How can I get the ID of the recordset, which is saved? I need it for saving informations into another table.

    Regards,
    Daniel

  182. Version 1.4.1 of the tutorial uses toArray. The SVN version of the code is correct, but I need to package up a zip file still.

    Regards,

    Rob…

  183. I use version 1.4.1

    After chapter 'Editing an Album' I get this notice in the input-fields:
    Trying to get property of non-object in /var/www/html/zend/site1/application/views/scripts/index/_form.phtml on line 5

    I compared my source code with the source code of 1.3 and I saw no differences.

    Regards,
    Peter

  184. After upgrade to ZendFramework-1.0.0-RC1 Im getting following exception for edit album.

    exception 'Zend_Exception' with message 'No entry is registered for key 'post" in C:Program FilesApache GroupApache2htdocstestzf-tutoriallibraryZendRegistry.php:145
    Stack trace:
    #0 C:Program FilesApache GroupApache2htdocstestzf-tutoriallibraryZend.php(298): Zend_Registry::get('post')
    #1 C:Program FilesApache GroupApache2htdocstestzf-tutorialapplicationcontrollersIndexController.php(103): Zend::registry('post')
    #2 C:Program FilesApache GroupApache2htdocstestzf-tutoriallibraryZendControllerAction.php(497): IndexController->editAction()
    #3 C:Program FilesApache GroupApache2htdocstestzf-tutoriallibraryZendControllerDispatcherStandard.php(230): Zend_Controller_Action->dispatch('editAction')
    #4 C:Program FilesApache GroupApache2htdocstestzf-tutoriallibraryZendControllerFront.php(889): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
    #5 C:Program FilesApache GroupApache2htdocstestzf-tutorialindex.php(84): Zend_Controller_Front->dispatch()
    #6 {main}

  185. Hi Rob

    In order to do a fully query, I called upon the $db object. In the following code, $news in equivalent to your $album. Here is some Controller code:

    $news = new News();
    $db = $news->getAdapter();
    $sql = 'SELECT id, nid, title, author, intro FROM news ORDER BY id DESC';
    $result = $db->fetchAll($sql);

    How do I transition from this back to the news object/view:
    $this->view->news = $news->fetchAll();

  186. Jude,

    With difficulty! If you use an SQL query, you have to create your own set of Zend_Db_Table_Rows.

    Alternatively, just use the array of results returned by fetchAll().

    Regards,

    Rob…

  187. Hi Rob

    Thanks for replying.

    I could not do the default fetchAll() because it shows the oldest news item first !!!

    Anyway, I solved the problem by putting the following code in the Controller file:

    $news = new News();
    $db = $news->getAdapter();
    $sql = 'SELECT id, nid, seg, title, author, pub_date, intro FROM news ORDER BY id DESC';
    $this->view->news = $db->fetchAll($sql);

    I followed it up by view scripts like the following:
    escape($val['title']) ?>

    Works well.

    Thanks a lot

  188. Jude,

    You should be able to do:


    < ?php
    $news = new News();
    $this->view->news = $news->fetchAll(null, 'id desc');

    Regards,

    Rob…

  189. Hi Rob

    Thanks. Even though I have an alternative, its nice to know you can do DESC even with the default fetchAll(). It looks simpler and neater

  190. Hello!

    I get this problem while checking the homepage through:
    http://localhost/zf-tutorial/
    on page 4 in the tutorial: getting-started-with-the-zend-framework_141

    Warning: include(./library/Zend/Loader.php) [function.include]: failed to open stream: Permission denied in /var/www/zf-tutorial/index.php on line 7

    Warning: include() [function.include]: Failed opening './library/Zend/Loader.php' for inclusion (include_path='.:./library:./application/models/:.:/usr/share/php:/usr/share/pear') in /var/www/zf-tutorial/index.php on line 7

    Fatal error: Class 'Zend_Loader' not found in /var/www/zf-tutorial/index.php on line 8

    Have i missed something?

    Best regards
    Mattias

  191. Mattias,

    The information you require is in the error message. It failed to open to the file library/Zend/Loader.php. Either the file is missing or your webserver doesn't have permission to read it.

    Regards,

    Rob…

  192. Hi Rob

    Since ZF RC3, 'index.php' appears on each URL for linked pages (except the default URL). Thus for a website called 'akra' and a Controller page called 'broadband', the default URL would be 'localhost/akra' and the broadband URL localhost/akra/index.php/index/broadband.

    In RC2, 'index.php' did not appear.

    I have tried conventional methods like adding some htaccess code to get rid of the index.php, but my efforts have been fruitless so far.

    Could you help?

  193. I had similar problems with RC3. I switched to using the latest nightly snapshot and everything worked fine again.

  194. Excellent tutorial how would I go about including data in the different pages. For example on the Add page if I wanted to list the last 5 added cds in a block on the right (much like in a forum, latest posts…)? How do I get the data and add it to the view?
    Thanks

  195. Simon,

    Thanks!

    I would use a view helper that accessed the model to collect the data required and displayed it as an unordered list. I'd then style with CSS.

    Regards,

    Rob…

  196. Rob,

    first of all, very nice tutorial! Thanks a lot!
    I'm reading version 1.4.1, using ZF 1.0 with PHP 5.2.3. After I've copied the IndexController.php file, I've tried to acess http://localhost/zf-tutorial/ but I got the following error: Zend_View_Exception: script 'index/index.phtml' not found in path (.applicationviewsscripts) in C:wampwwwzf-tutoriallibraryZendViewAbstract.php on line 856.
    After research, I reach the following solution:
    add the following line to
    your bootstrap, prior to the call to dispatch():

    // Assuming $front is the front controller instance:
    $front->setParam('noViewRenderer', true);
    $front->dispatch();

    Best wishes,

    Thiago melo de Paula

  197. Rob,
    I am having a problem right from the beginning and can't seem to get past it. I have rewrite working correctly, but for some reason I get the following error on page 6, and it has be pretty baffled:

    Fatal error: Uncaught exception 'Zend_View_Exception' with message 'script 'index/index.phtml' not found in path (./application/views/scripts/)' in /usr/share/php/library/Zend/View/Abstract.php:856 Stack trace: #0 /usr/share/php/library/Zend/View/Abstract.php(764): Zend_View_Abstract->_script('index/index.pht…') #1 /usr/share/php/library/Zend/Controller/Action/Helper/ViewRenderer.php(732): Zend_View_Abstract->render('index/index.pht…') #2 /usr/share/php/library/Zend/Controller/Action/Helper/ViewRenderer.php(753): Zend_Controller_Action_Helper_ViewRenderer->renderScript('index/index.pht…', NULL) #3 /usr/share/php/library/Zend/Controller/Action/Helper/ViewRenderer.php(800): Zend_Controller_Action_Helper_ViewRenderer->render() #4 /usr/share/php/library/Zend/Controller/Action/HelperBroker.php(160): Zend_Controller_Action_Helper_ViewRenderer->postDispatch() #5 /usr/share/php/library/Zend/Controller/Action.php(504): Zend_Controller_Action_HelperBroker->notifyPostDispatch() #6 /usr/share/php/library/Zend/Controller/Dispatc in /usr/share/php/library/Zend/View/Abstract.php on line 856

    If I create the file '/zf-tutorial/application/scripts/index/index.phtml' the application completes as expected. Please help. What am I missing?

  198. great job!
    1 a tips to share with someone got "mysql driver not installed"error;
    I found it very easy to set up in a shared Host, where I use bluehost,because they didn't install PDO, so later I figured out to change the /application/config.ini line1 into db.adatper=MYSQLI, and everything in this tutorials just works!

    2,I read all the tutorial against the Zend Framework API but still one little problem that I can't seem to understand :
    in an action function,what does this second arrow mean in " $this->view->baseUrl=$this->_request->getBaseUrl();"?

    because "baseUrl" is not an variable in view class nor is it a method in View, so here it just is a temporary name that can be used in the corresponding phtml file .the thing I can't understand is that when any object of view class is created all the fields and methods shoud be predefined .how can we add a runtime virable to an object? is this mechanism by PHP5 or by the Zend Framework?

    and still when I tried to delete all the "baseUrl" name in that phtml file,I supposed that there will be some error message in the controller like "undefined method or variable" but It doesn't.So I think the framework doesn't rap the view and phtml as an object.or this is just some mechanism to pass variable not strictly by OO concept?
    I can't find a clue in the API.

    I am new to php and did some java and ruby,so I must missed something here and hope you guys can give me some idea,,thanks!

  199. Just a note, the zipped source files still contain these lines:

    // setup database
    $db = Zend_Db::factory($config->db->adapter, $config->db->config->asArray());

    which should be:

    // setup database
    $db = Zend_Db::factory($config->db->adapter, $config->db->config->toArray());

  200. re: harry

    $this->view->baseUrl
    creates the variable baseUrl for the view that belongs to the action you are in: This action's view's baseUrl.

    $this->_request->getBaseUrl()

    calls getBaseUrl in the _request object for this action.

    Hope that helps!

  201. Hi,
    when i downloaded the pdf file (for zend 1.0.0) and tried the tutorial out the error that i got was as follows:

    Server error!

    The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there was an error in a CGI script.

    If you think this is a server error, please contact the webmaster.
    Error 500
    localhost
    07/18/07 10:03:10
    Apache/2.2.4 (Win32) DAV/2 mod_ssl/2.2.4 OpenSSL/0.9.8d mod_autoindex_color PHP/5.2.1

    i want to know what is it am i doing wrong? And could some one please explain to me this statement.

    "…Note that the php_flag setting in .htaccess only works if you are using mod_php. If you use CGI/FastCGI, then you need to make sure that your php.ini is correct."

    Please do help,Thanks.

  202. Hi, i have a strange problem.
    I do use this settings in .htaccess
    RewriteEngine on
    RewriteRule .* index.php
    All things works if i write urlToSite/index or urlToSite/index.php, but if i only write urlToSite then i do get this error msg

    Not Found

    The requested URL /PathToPage/index.php was not found on this server.

    But the file is there with the right path. If i remove my .htaccess file and goes to urlToSite then i see index.php. Do you see anything wrong in my .htaccess

  203. there is some errores!
    Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception' with message 'Invalid controller specified (ex)' in C:app_php5zend_applibraryZendControllerDispatcherStandard.php:194 Stack trace: #0 C:app_php5zend_applibraryZendControllerFront.php(911): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #1 C:app_php5zend_appindex.php(28): Zend_Controller_Front->dispatch() #2 {main} thrown in C:app_php5zend_applibraryZendControllerDispatcherStandard.php on line 194

    I have followed your tutorial.
    Thanks!

  204. I cant run the example. Only have this message if i want to ckeck the URLs.

    Not Found
    The requested URL /zf-tutorial/index was not found on this server.
    Apache/2.0.54 (Win32) PHP/5.1.6 mod_auth_sspi/1.0.1 Server at PC1 Port 80

    I test it with:
    /zf-tutorial/index
    /zf-tutorial/index/index
    /zf-tutorial/index/add
    /zf-tutorial/index/edit
    /zf-tutorial/index/delete

    I dont find the error. Please i need some help

    my .htaccess is:
    RewriteEngine on
    RewriteRule .* index.php
    php_flag magic_quotes_gpc off
    php_flag register_globals off

    I use Apache 2.0.54, PHP 5.1.6.

  205. I've a question regarding the common used view scripts. You set the data for these scripts in the init() method of controller (e.g. title or baseURL). But I have to to this in every controller, which want to use it.
    First idea is subclassing the action controller for common use of init method, but I find it not very elegant.
    Can you recomment a place?

    Great jop!
    Thanks, Falk.

  206. Hey Robby! :)
    Actually you're the only one, who provides a tutorial for zf 1.0.0 -great job!
    But I wouldn't leave a reply if I hadn't any trouble though ;)
    My Problem is: For don't hardcode the same HTML in every template, you added a "echo $this->render('header.phtml');" n the 'index.phtml' file. (Also one for the footer…)
    At this point, i get an error:
    "script 'header.phtml' not found in path (./application/views/scripts/)"
    I'm not very used to zf, all i did was following your instructions …
    I've checked every line of my code, things seem to be okay.
    Any ideas?

    Btw: Thx for your help, this tutorial is just great :)

  207. Agustin & Nicolas,

    Turn on the mod_rewrite extension in your Apache httpd.conf file. It's off by default in a standard Windows installation.

    Regards,

    Rob…

  208. phpdummi,

    I'm more of a Rob, than a Robby!

    Have you put your header.phtml into the views/scripts directory? If so, I'd check the permissions on it.

    Regards,

    Rob…

  209. Hi … Rob!
    Sorry for making you trouble, but I've spend more than 1hour to get rid of this errormessage :x
    Now, after reading carefully what answered, I checked again … and there it was! I was so dump to put the header- and footer.phtml into the views/scripts/index folder, instead of just views/scripts.
    Thx for your competent answer, commitable!
    Great tutorial, indeed.

  210. Hi,
    I like your tutorial but I have a problem. I followed tutorial step by step but nothing happened so I copied your code and still nothing. I try to access index.php (with code from the first step) and nothing happens. I mean I don't get any Fatal error! Can you help me please?

    Mingan

  211. It'd be better to solve the problem, if you explain WHAT happens!
    Do you get a white page, or what?
    Maybe your ModRewrite module isnt't working…

  212. Hi roben,
    I would like to congrat you for this wonderfull article. And I would suggest an article with Zend Framework and Ajax applications.
    Keep with the good work.

    Cya,
    Felipe Tonello

  213. Hi Rob,

    First:
    Thanks for this great tutorial, keep up the good work!

    Second:
    I am having a little trouble with the following lines in Album.php:

  214. ok, seems your guestbook cut the last half of my post. Lets assume I copied the code for the Album.php from your latest pdf:

    I cant get the Album.php to work due to a parse error (expectin 'T_OLD_FUNCTION' or 'T_FUNCTION' or '}').

    I am using the latest MAMP version on a MAC OS X 10.4, means php 5 should be running properly.

    Any ideas?

    Many thanks,
    blaxx

  215. Thanks for a super tutorial. I'm half way through. I'd just thought I'd mention that I got a bit hung-up when I got to the ADD action and saw:
    "// set up an "empty" album
    $this->view->album = new stdClass();"

    I was wondering where on earth the stdClass came from and what is was. After a search on Google I found out that "stdClass is a skeleton class, a blank canvas if you like". Could be worth adding a little explanation in the tutorial if your feeling extra nice ;o)

    Not only am I new to Zend Framework, but I'm quite new to OOP aspects of PHP.

  216. There's a better way now as you can use nowadays.


    $albums = new Album();
    $this->view->album = $albums->createRow();

    Regards,

    Rob…

  217. Great tutorial, I just seem to be a bit st00pid…

    Now ZF has come out of beta, I'm willing to give it a serious try, but I already got stuck at the simple task of following this tut. Espescially the part with the view on page 7.

    Where do I have to create the Zend_View object? In the controller file, in the bootstrap file or somewhere else altogether?

    I keep getting an error/exception right now:

    ====================================
    Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception' with message 'Invalid controller specified (product)' in C:xamppxampphtdocstiesupplylibraryZendControllerDispatcherStandard.php:193
    Stack trace:
    #0 C:xamppxampphtdocstiesupplylibraryZendControllerFront.php(911): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
    #1 C:xamppxampphtdocstiesupplyindex.php(21): Zend_Controller_Front->dispatch()
    #2 {main}
    thrown in C:xamppxampphtdocstiesupplylibraryZendControllerDispatcherStandard.php on line 193
    ====================================

    I'm running Apache2.2.3 , PHP 5.2.0 and ZF 1.0… Although I still haven't included the view object, I doubt that this error has anything to do with that. Right?

    What am I doing wrong?

  218. Little change in my message above (#365):
    ====================================
    Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception' with message 'Invalid controller specified (index)' in C:xamppxampphtdocszftestlibraryZendControllerDispatcherStandard.php:193
    Stack trace:
    #0 C:xamppxampphtdocszftestlibraryZendControllerFront.php(911): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
    #1 C:xamppxampphtdocszftestindex.php(21): Zend_Controller_Front->dispatch()
    #2 {main}
    thrown in C:xamppxampphtdocszftestlibraryZendControllerDispatcherStandard.php on line 193
    ====================================

    I changed everything back to exactly follow the tutorial.

    Now if I go to: http://localhost/zftest/ or
    http://localhost/zftest/index/

    I get the exeption above…

    I did set the baseUrl to 'zftest', so that should solve that problem, right?

  219. I have a question about the zend_search_lucene part.
    When I create a index using:
    $doc->addField(Zend_Search_Lucene_Field::UnStored('contents', $content));

    In windowsXP, it works well and create one _0.cfs file which contains some information about the content.

    However, when I tried to migrate it to solaris10 os(Sunos sun4u sparc SUNW), it create a _0.cfs file but with nothing indexed in the file.

    Is it related to the os or the character set? I have tried many solutions, but still cannot get through this problem.

  220. @ comment 362/363

    Beeing the noob that i am:

    I'm not entirely sure how i would replace this:

    // set up an "empty" album
    $this->view->album = new stdClass(); $this->view->album->id = null; $this->view->album->artist = "; $this->view->album->title =";

    with this:

    $albums = new Album();
    $this->view->album = $albums->createRow();

    And what is the benefit?

  221. Thanks for your reply.

    Just mentioning one other thing I got a bit 'hung up' on when reading through the tutorial. Although you tell us to turn magic_quotes_gpc Off I notice that the user provided data doesn't seem to have addslashes applied anywhere else in the script. After reading John Baldock's comment, above, I discover that the Zend framework does its own form of magic quoting. So, again, if you are feeling nice, it would be worth mentioning that in the tutorial. (I spent a long time searching the framework docs for any mentions of magic quoting to no avail – i think there should be section in the docs explaining when to quote and when not to quote).

  222. Hi :)

    So lets say that there's no albums in the database. When i do a fetchall and want to check if theres no data in it i do a simple

    if ($this->albums) :
    print some albums here
    else :
    print no albums added
    endif

    – but as i see it, it doesnt print the no albums thing. the reason must be that it exists, but it doesnt contain data, but still exists

    is there any workaround when using the fetchall?

  223. I get to the top of page 14 of 18 in the tutorial, just be fore the heading "Adding More Albums" and run the site expecting to see the two records. Instead I get the following:

    Fatal error: Uncaught exception 'Zend_View_Exception' with message 'script 'footer.phtml' not found in path (./application/views/scripts/)' in /home/clmitch1/public_html/zf_tutorial/library/Zend/View/Abstract.php:856 Stack trace: #0 /home/clmitch1/public_html/zf_tutorial/library/Zend/View/Abstract.php(764): Zend_View_Abstract->_script('footer.phtml') #1 /home/clmitch1/public_html/zf_tutorial/application/views/scripts/index/index.phtml(20): Zend_View_Abstract->render('footer.phtml') #2 /home/clmitch1/public_html/zf_tutorial/library/Zend/View.php(46): include('/home/clmitch1/…') #3 /home/clmitch1/public_html/zf_tutorial/library/Zend/View/Abstract.php(768): Zend_View->_run('./application/v…') #4 /home/clmitch1/public_html/zf_tutorial/library/Zend/Controller/Action/Helper/ViewRenderer.php(742): Zend_View_Abstract->render('index/index.pht…') #5 /home/clmitch1/public_html/zf_tutorial/library/Zend/Controller/Action/Helper/ViewRenderer.php(763): Zend_Controller_Action_Helper_ViewRenderer->renderScript('index/index.pht…', in /home/clmitch1/public_html/zf_tutorial/library/Zend/View/Abstract.php on line 856

  224. "Notice how we check the $_SERVER['REQUEST_METHOD'] variable to see if the form has been submitted."

    No, I don't since you use $this->_request->isPost() ;-).

    Nice tutorial, just reading it though ATM. I hope to be able to follow it more closely soon.

  225. Thanks for this tutorial. It suited me very well.

    very good for an entry to zend framework.

    Now to time to check out your Zend_Auth tutorial as well :)

    -trond

  226. Like so many others have already said, "Thank you" for this tutorial. It has been very difficult to find one that works with 1.* version of the framework.

    That said, I've been able to find most of my typos and correct them w/o bothering you, but I can not find my problem on this one:

    I'm able to get everything to work except the actions for "add" and "edit". (Index list works fine and the display of add/edit works.)

    I'm using framework ver: 1.0.1 and tutorial version 1.4.4 on LAMP.

    When I click on the Add button to create a new record I get these messages:

    Fatal error: Uncaught exception 'Zend_Controller_Action_Exception' with message 'IndexController::add20methodAction() does not exist and was not trapped in __call()' in /var/www/html/zf-tutorial/library/Zend/Controller/Action.php:480 Stack trace: #0 [internal function]: Zend_Controller_Action->__call('add20methodActi…', Array) #1 /var/www/html/zf-tutorial/library/Zend/Controller/Action.php(497): IndexController->add20methodAction() #2 /var/www/html/zf-tutorial/library/Zend/Controller/Dispatcher/Standard.php(237): Zend_Controller_Action->dispatch('add20methodActi…') #3 /var/www/html/zf-tutorial/library/Zend/Controller/Front.php(911): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #4 /var/www/html/zf-tutorial/index.php(30): Zend_Controller_Front->dispatch() #5 {main} thrown in /var/www/html/zf-tutorial/library/Zend/Controller/Action.php on line 480

    My URL is: http://localhost/zf-tutorial/index/add%20method=?artist=dave&title=test&id=&add=Add

    I'm confused by the "%20" that is in the URL. I've looked for a Space (specifically in the action value), but can not find anything wrong. I've also tried to change the baseUrl value, but that doesn't seem to make any difference either.

    Any help would be appreciated. Thanks.

  227. I finally found a tutorial that follow my personal favorite rule for programming: KISS!

    Congratulations.

  228. Sorry, I should have said that I knew it is an encoded space. I'm not sure why it is there or if it is an indication of the problem.

    I feel confident that I've coded everything the way it is in the tutorial with the possible exception of a typo. I have 20+ years of I/T experience so I wouldn't consider myself a noob to programming. I am a noob to ZF.

    I have desk-checked my code several times, but I'm unable to determine the cause of the problem. Would anyone have a specific idea of what is causing the problem? I do have my "addAction()" function in zf-tutorial/controller/IndexController.php

    Thanks.

  229. Referencing #383 & 386, I found that I didn't have the closing quote on the form action.

    Rob, keep up the good work.

  230. hi Rob,
    thanks for the great tutorial!! I got it all working on localhost with WAMP, but when I uploaded the example to my webhost, i just get 404 not found error :(

    what could be the problem?
    thanks :)
    pyko

  231. I cannot get your code to work. The index.php loads ok with the list of albums. But none of the links (add, edit, delete) work for me.

    "The requested URL /zf_albums/index.php/index/edit/id/1 was not found on this server."

  232. Hi Rob,

    thanks for your tutorial and the time you are spending in supporting this ;-))

    Because I don't know, how to go forward, it would be nice to get yet another part of this tutorial.

    For example, if there is a table for artists (id, name) and in albums in the fild artist there is a reference to artists.id

    Regards,

    Daniel

  233. Hi Rob,

    I don't quite understand part of the editAction function in IndexController.php.

    "if ($id !== false){…}else{…}"

    What does "!==" mean? Is it possible that ($id === flase) evaluates to true? Could you please give me an example scenario of the program executing the code within the braces after else?

    Thanks.

  234. Dix Mars,

    This:
    if ($id !== false){…}else{…}

    Means:
    if $id is not EXACTLY equal in value and type (false, boolean) then this statement is false.

    Example:
    ( (0) !== false) (this is true)
    ( (0) != false) (this is false)
    ( " !== false) (this is true)
    ( " != false) (this is false)

  235. hi
    I already test your code in localhost
    The index.php load ok with the list of albums. But none of the links (add, edit, delete) work for me , message was Page Not Found
    http://localhost:8090/zf-tutorial/index/add

    already set mod_rewrite in httpd.conf uncommented LoadModule rewrite_module modules/mod_rewrite.so and test wiht phpinfo() mod_rewrite is ok can you tell me why ? and Zend Lib already in library ZF-tutorial ?

    but there was error in log apache
    [Tue Aug 28 14:16:41 2007] [error] [client 127.0.0.1] File does not exist: D:/Program Files/Apache Group/Apache2/htdocs/zf-tutorial/index

  236. hi
    I already test your code in localhost
    The index.php load ok with the list of albums. But none of the links (add, edit, delete) work for me , message was Page Not Found
    http://localhost:8090/zf-tutorial/index/add

    already set mod_rewrite in httpd.conf uncommented LoadModule rewrite_module modules/mod_rewrite.so and test wiht phpinfo() mod_rewrite is ok can you tell me why ? and Zend Lib already in library ZF-tutorial ?

    but there was error in log apache
    File does not exist: D:/Program Files/Apache Group/Apache2/htdocs/zf-tutorial/index

  237. Is anyone else finding you cannot edit an album. It goes back to the homepage after pressing the edit button, but the changes are not saved to the database.

    Is there a way of displaying the last SQL query used by Zend_Db_Table?

  238. Hi, Rushy2uk,

    If memory serves, you should change the name attribute of the hidden input in _form.phtml from 'ID' to 'id', as in the controller, it tries to getPost('id') rather than getPost('ID').

    It cost me a whole night to debug this. Anyway, is PHP case-sensitive?

  239. Dix, Rushy2uk

    In this case, PHP is case-sensitive in terms of array elements.
    i.e.

    $array['ORANGE'] is not the same as $array['orange']

    Regards,

    Rob…

  240. Excellent tutorial.
    Really excellent.
    Makes it so simple to really get a solid grounding in the basic concepts.
    I read heaps of "getting started" type tutorials and none of them were even close to satisfying…
    Thanks. :-)

  241. This tutorial has been a great starting point for me!

    It would be wise however to add a note to this tutorial that in case of applying the _redirect method, output buffering should be ON (in php.ini or .htaccess) otherwise an exception error (headers already sent) will be raised!!

  242. My baseUrl is domain.com/tutorial. I've put tutorial code (with zf and changed config.ini) there.
    I've set BaseUrl with setBaseUrl in front controller setup to '/tutorial/'.

    And I've a problem.

    If I use link to add, edit or delete action – everything is OK. But when I'm then trying to use a button ('Add', 'Update' or 'Yes') – I've got a problem:
    – 'Add' and 'Update' makes correct changes to db, but there is no redirect then;
    – 'Delete' also makes changes (delete album) but there is 500 Internal Error then.

    So the problem is $this->_redirect('/'); or something other with redirection.

    When I've put options to redirect (array('code'=>303)) deleteAction redirect correctly to album list.
    But add and edit action still make no difference.

    Can you help me?

  243. Huh – nothing (i've looked over api doc).

    But I found that if I echo single space (echo ' ';) before usage of _redirect – everything is OK.
    But this isn't feasible solution.

  244. This has everything a great tutorial should be: simple enough to follow, complex enough to be useful, and logical enough to be understood. Thanks a million :-)

    One comment on the _form.phtml: since this form is used by both the Add and Edit pages, I would be inclined to use

    escape($this->action); ?>"

    instead of

  245. nice filtering :-)
    one more time … use

    type="submit" name="?php echo $this->escape($this->action); ?"

    instead of

    type="submit" name="add"

  246. Hi!, I'm doing the tutorial an I have a problem on Album List, I recibe this message:

    Notice: Trying to get property of non-object in C:xampphtdocszf-tutorialindex.php on line 22

    Notice: Trying to get property of non-object in C:xampphtdocszf-tutorialindex.php on line 22

    Fatal error: Call to a member function toArray() on a non-object in C:xampphtdocszf-tutorialindex.php on line 22

    Can tell me where can be happening??!
    Thanks a lot, elis

  247. I receive this error and i don´t know how to solve it because the table album has a primary key: (i`m usign PDO_Sqlite adapter, there is another way to connect to mysql widthout an adapter?!)

    Fatal error: Uncaught exception 'Zend_Db_Table_Exception' with message 'Primary key column(s) (id) are not columns in this table ()' in /var/www/html/zf-tutorial/library/Zend/Db/Table/Abstract.php:651 Stack trace: #0 /var/www/html/zf-tutorial/library/Zend/Db/Table/Abstract.php(529): Zend_Db_Table_Abstract->_setupPrimaryKey() #1 /var/www/html/zf-tutorial/library/Zend/Db/Table/Abstract.php(264): Zend_Db_Table_Abstract->_setup() #2 /var/www/html/zf-tutorial/application/controllers/IndexController.php(15): Zend_Db_Table_Abstract->__construct() #3 /var/www/html/zf-tutorial/library/Zend/Controller/Action.php(497): IndexController->indexAction() #4 /var/www/html/zf-tutorial/library/Zend/Controller/Dispatcher/Standard.php(237): Zend_Controller_Action->dispatch('indexAction') #5 /var/www/html/zf-tutorial/library/Zend/Controller/Front.php(911): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #6 /var/www/html/zf-tutorial/index.php(42): Zend_Controller_Front-> in /var/www/html/zf-tutorial/library/Zend/Db/Table/Abstract.php on line 651

    Thanks very much, elisa

  248. Hello,

    First of all Thanks A Lot for the tutorial, A great way know about ZF.

    I am a newbie in Zend Framework and used your ex. code for studies. But now I am STUCK. Everthing is fine except PDO… I have WAMP with PHP 5.2.3 and MySQL 5.0.41 installed in my XP machine. Also my PDO are set ON.

    extension=php_pdo.dll
    extension=php_pdo_sqlite.dll
    extension=php_pdo_mysql.dll

    But when I am running the index.php from "http://localhost/~test/" its showing error message:

    Fatal error: Uncaught exception 'Zend_Db_Adapter_Exception' with message 'The mysql driver is not currently installed' in C:wampwwwtestlibraryZendDbAdapterPdoAbstract.php:104 Stack trace: #0 C:wampwwwtestlibraryZendDbAdapterAbstract.php(263): Zend_Db_Adapter_Pdo_Abstract->_connect() #1 C:wampwwwtestlibraryZendDbAdapterPdoAbstract.php(206): Zend_Db_Adapter_Abstract->query('DESCRIBE `album…', Array) #2 C:wampwwwtestlibraryZendDbAdapterPdoMysql.php(138): Zend_Db_Adapter_Pdo_Abstract->query('DESCRIBE `album…') #3 C:wampwwwtestlibraryZendDbTableAbstract.php(595): Zend_Db_Adapter_Pdo_Mysql->describeTable('album', NULL) #4 C:wampwwwtestlibraryZendDbTableAbstract.php(528): Zend_Db_Table_Abstract->_setupMetadata() #5 C:wampwwwtestlibraryZendDbTableAbstract.php(264): Zend_Db_Table_Abstract->_setup() #6 C:wampwwwtestapplicationcontrollersIndexController.php(32): Zend_Db_Table_Abstract->__construct() #7 C:wampwwwtestlibraryZendControllerAction.php(497): Index in C:wampwwwtestlibraryZendDbAdapterPdoAbstract.php on line 104

    WHAT DID I DO WRONG? I am sitting in front of it for 3 days and there is no imporvemnet :(. Please help me. Thanks a lot in advance!!!

  249. Hello,

    Dont bother about my message… I got it fixed at last… The problem was with multiple config files (php.ini), as Rob as explained earlier "Multiple php.ini files in a system can cause a world of pain"… I am releaved :)

  250. Hello!

    Since this is a place where everybody is discussing, I want to know if someone can fix my problem!

    I'm actually having some problems using PDO_PGSQL and schemas. Following the tutorial present on this site, I've made the necessary modifications to run the zf-tutorial on Postgre, and that worked. After that, I brought to my work the idea of using ZendFramework, and everybody LIKED it!

    The problem started when I needed to configure a schema (let's say for now, the "foo" schema). On the model constructor I needed to pass one more string on the array wich was the schema name string. But it doesn't find any of the relations!

    I always get an error message telling me that no relation was found. But if I put my tables on the public schema, everything works fine! I've already tried hundreds of configurations, and readed the whole code of Zend_Db, but didn't figured the problem out.

    Am I missing something? Can someone help me? Is this a bug with PDO?

    Sorry for my bad english, I'm brazilian :)

    Marc Abillama

  251. For Mac Users: So I spent about 3 days trying to figure out why I was getting an Internal Server 500 error, and I've finally figured it out. I noticed some other people had the same problem, so I figured I'd share with you guys…

    I've been editing the .htaccess file (with the Rewrite rules) in TextEdit. Turns out, TextEdit adds Mac line breaks, causing the server to get confused. Instead, I downloaded TextWrangler (from the guys at BareBones), made sure I saved the .htaccess file with Unix line breaks, and voila! The Zend Framework works like a charm. Also – TextWrangler allows you to open "Hidden" files, so you don't have to use some crazy tool (like TinkerTool) to display hidden files on your Mac.

    I'm relatively new to Mac's, so I'm used to Windows Notepad, which edited .htaccess files easily.

    Now I can sleep better…

  252. nice tutorial but that would be greater if you show how to connect different tables (posts with comments, albums and categories, etc). i still don't get it.

    any other framework presentation tutorials(cakephp, ror, symfony) shows how to create blog. this is very usefull and show the way to create almost anything (like forum, news, tags, etc).

    please add this thing to tutorial or just explain this important feature in comments. thank you.

  253. Absolutely fantastic tutorial! Exactly what I needed to get me started with the Zend Framework.

    I think that the tutorial should stick to the Zend Coding style guidlines just to be complete. I know it's picky but strings should be single quoted!

    Thanks for this!

  254. Hey guys why is it 'echo $this->_request->getBaseUrl();'
    doesn't seem to output anything :s ?

    ps:, Thank you for this great tutorial, it really help me a lot on startin ZF.

  255. Zend Framework has unveiled the version 1.0.2, I hope your tutorial code can also upgraded.

    huangam

  256. Hi, nice tutorial.
    But I am having the following error can you help.

    Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception' with message 'Invalid controller specified (zf-tutorial)' in /var/www/html/zf-tutorial/library/Zend/Controller/Dispatcher/Standard.php:193 Stack trace: #0 /var/www/html/zf-tutorial/library/Zend/Controller/Front.php(911): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #1 /var/www/html/zf-tutorial/index.php(33): Zend_Controller_Front->dispatch() #2 {main} thrown in /var/www/html/zf-tutorial/library/Zend/Controller/Dispatcher/Standard.php on line 193

  257. I'm getting the following errors:
    Strict Standards: Implicit cloning object of class 'Zend_Controller_Plugin_Broker' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerFront.php on line 152

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Front' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerFront.php on line 163

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Front' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerFront.php on line 166

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Front' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutorialindex.php on line 10

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Front' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerFront.php on line 774

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Dispatcher_Standard' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerDispatcherAbstract.php on line 306

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Dispatcher_Standard' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerFront.php on line 583

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Dispatcher_Standard' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerFront.php on line 585

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Front' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerFront.php on line 246

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Front' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerFront.php on line 274

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Plugin_ErrorHandler' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerPluginErrorHandler.php on line 117

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Plugin_ErrorHandler' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerPluginBroker.php on line 60

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Plugin_ErrorHandler' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerPluginBroker.php on line 72

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Plugin_Broker' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerPluginBroker.php on line 83

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Action_Helper_ViewRenderer' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerActionHelperBroker.php on line 70

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Action_Helper_ViewRenderer' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerActionHelperBroker.php on line 73

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Request_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerRequestHttp.php on line 351

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Request_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerFront.php on line 829

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Request_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerFront.php on line 437

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Request_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerFront.php on line 447

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Front' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerFront.php on line 449

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Response_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerFront.php on line 849

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Response_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerFront.php on line 600

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Response_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerFront.php on line 610

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Front' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerFront.php on line 612

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Request_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerPluginBroker.php on line 174

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Request_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerPluginBroker.php on line 176

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Plugin_ErrorHandler' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerPluginBroker.php on line 178

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Request_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerPluginAbstract.php on line 53

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Request_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerPluginAbstract.php on line 55

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Plugin_ErrorHandler' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerPluginAbstract.php on line 56

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Plugin_Broker' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerPluginBroker.php on line 182

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Response_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerPluginBroker.php on line 201

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Response_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerPluginBroker.php on line 203

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Plugin_ErrorHandler' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerPluginBroker.php on line 205

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Response_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerPluginAbstract.php on line 75

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Response_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerPluginAbstract.php on line 77

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Plugin_ErrorHandler' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerPluginAbstract.php on line 78

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Plugin_Broker' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerPluginBroker.php on line 210

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Router_Rewrite' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerRouterAbstract.php on line 95

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Router_Rewrite' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerFront.php on line 475

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Router_Rewrite' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerFront.php on line 485

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Front' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerFront.php on line 487

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Router_Rewrite' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerFront.php on line 504

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Router_Rewrite' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerFront.php on line 863

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Router_Rewrite' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerRouterAbstract.php on line 95

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Dispatcher_Standard' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerFront.php on line 585

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Dispatcher_Standard' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerFront.php on line 869

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Dispatcher_Standard' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerDispatcherAbstract.php on line 306

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Response_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerDispatcherAbstract.php on line 367

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Response_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerDispatcherAbstract.php on line 369

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Dispatcher_Standard' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerDispatcherAbstract.php on line 370

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Request_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerPluginBroker.php on line 231

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Plugin_ErrorHandler' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerPluginBroker.php on line 233

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Request_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerPluginAbstract.php on line 98

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Request_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerRouterRewrite.php on line 233

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Front' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerFront.php on line 166

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Front' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerRouterAbstract.php on line 164

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Front' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerRouterAbstract.php on line 165

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Dispatcher_Standard' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerDispatcherAbstract.php on line 306

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Dispatcher_Standard' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerFront.php on line 583

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Dispatcher_Standard' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerFront.php on line 585

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Dispatcher_Standard' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerRouterRewrite.php on line 70

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Front' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerRouterAbstract.php on line 159

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Dispatcher_Standard' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerRouterRouteModule.php on line 92

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Dispatcher_Standard' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerRouterRouteModule.php on line 102

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Router_Route_Module' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerRouterRewrite.php on line 74

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Request_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerRequestHttp.php on line 432

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Request_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerRequestHttp.php on line 544

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Router_Route_Module' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerRouterRewrite.php on line 247

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Request_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerRouterRewrite.php on line 259

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Request_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerRequestAbstract.php on line 283

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Request_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerRequestHttp.php on line 578

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Request_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerRequestAbstract.php on line 126

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Request_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerRequestAbstract.php on line 283

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Request_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerRequestHttp.php on line 578

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Request_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerRequestAbstract.php on line 152

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Request_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerRequestAbstract.php on line 283

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Request_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerRequestHttp.php on line 578

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Request_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerRequestAbstract.php on line 100

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Request_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerRouterRewrite.php on line 255

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Request_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerPluginBroker.php on line 254

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Plugin_ErrorHandler' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerPluginBroker.php on line 256

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Request_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerPluginAbstract.php on line 109

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Request_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerPluginBroker.php on line 281

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Plugin_ErrorHandler' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerPluginBroker.php on line 283

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Request_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerPluginAbstract.php on line 118

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Request_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerRequestAbstract.php on line 326

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Request_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerPluginBroker.php on line 303

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Plugin_ErrorHandler' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerPluginBroker.php on line 305

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Request_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerPluginAbstract.php on line 132

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Request_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerDispatcherStandard.php on line 183

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Response_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerDispatcherStandard.php on line 183

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Response_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerDispatcherAbstract.php on line 367

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Response_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerDispatcherAbstract.php on line 369

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Dispatcher_Standard' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerDispatcherAbstract.php on line 370

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Request_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerDispatcherStandard.php on line 158

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Request_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerDispatcherStandard.php on line 308

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Request_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerDispatcherStandard.php on line 360

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Request_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerRequestAbstract.php on line 126

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Request_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerRequestAbstract.php on line 152

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Front' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerFront.php on line 166

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Front' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerDispatcherAbstract.php on line 265

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Front' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerDispatcherAbstract.php on line 268

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Front' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerDispatcherAbstract.php on line 268

    Strict Standards: Implicit cloning object of class 'Zend_Controller_Request_Http' because of 'zend.ze1_compatibility_mode' in C:wampwwwzf-tutoriallibraryZendControllerRequestAbstract.php on line 100

    Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception' with message 'Cannot load controller class "IndexController" from file "IndexController.php" in directory ""' in C:wampwwwzf-tutoriallibraryZendControllerDispatcherStandard.php:284 Stack trace: #0 C:wampwwwzf-tutoriallibraryZendControllerDispatcherStandard.php(208): Zend_Controller_Dispatcher_Standard->loadClass('IndexController') #1 C:wampwwwzf-tutoriallibraryZendControllerFront.php(920): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #2 C:wampwwwzf-tutorialindex.php(15): Zend_Controller_Front->dispatch() #3 {main} thrown in C:wampwwwzf-tutoriallibraryZendControllerDispatcherStandard.php on line 284

  258. Hi Rob,
    This is really the best tutorial (v.1.4.5) i have seen about ZF. Thank you. I have added setCredentialTreatment to login action to use mysql password functionality.

    I m just curious that what you think about complex views (pages) in ZF, as i read there are some serious discussions going out there.

    I m really stuck with the idea of implementing a complex page which includes, ajax, flash, html.

    I ll be really thankful if you can write about complex views, at least please provide useful links u have.

    Thank you again for this tutorial.
    Bulent.

  259. Hello there…

    Well, lot of problems with the PDO installation on my hosting server. So, I can´t use PDO_MYSQL in the config.ini.

    Then two days of google "Zend without PDO", and (this look good, but… checkout your self), for me don't function at all.

    http://devzone.zend.com/node/view/id/1553

    So, finally, third day of deseperation, I change the controller in the confing.ini to MYSQLI and I GOT IT!!!!… YES.. FUNCTION.

  260. Hi Rob,

    I was wondering how can I use the "join" command in this example. I've been trying it myself but to no avail:

    Zend_Loader::loadClass('Booksdata');
    Zend_Loader::loadClass('Author');

    $booknum = (int)$this->_request->getParam('booknum', 0);
    $booksdata = new Booksdata();
    $booksdata->fetchRow('booknum='.$booknum);
    $booksdata->getAdapter();
    $sql = $db->select();
    $sql->from('booksdata', '*');
    $sql->where('booksdata.booknum =?', $booknum);
    $this->view->booksdata=$db->fetchall($sql);

    I wanted to left join the table "author" into table "booksdata".
    Your help would greatly be appreciated.

    Many thanks from the Philippines!

  261. Fatal error: Uncaught exception 'Zend_Controller_Action_Exception' with message 'IndexController::deleteAction() does not exist and was not trapped in __call()' in D:xampphtdocszf-tutoriallibraryZendControllerAction.php:480 Stack trace: #0 [internal function]: Zend_Controller_Action->__call('deleteAction', Array) #1 D:xampphtdocszf-tutoriallibraryZendControllerAction.php(497): IndexController->deleteAction() #2 D:xampphtdocszf-tutoriallibraryZendControllerDispatcherStandard.php(238): Zend_Controller_Action->dispatch('deleteAction') #3 D:xampphtdocszf-tutoriallibraryZendControllerFront.php(920): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #4 D:xampphtdocszf-tutorialindex.php(31): Zend_Controller_Front->dispatch() #5 {main} thrown in D:xampphtdocszf-tutoriallibraryZendControllerAction.php on line 480

    all actions are working except delete
    can any one help pls

  262. I am receiving an identical message to jay (post #445), I checked the spelling and it is correct.

    (Delete if the only element not working.)

    Thank you for your help. Thank you for taking the time to write this excellent tutorial.

  263. Well, after much tinkering with the code…for some reason, adding another closing curly brace at the end of the deleteAction() function corrected everything. However, that curly brace does not seem to be connected to anything…so I am going to double-check all the segments of code. Problem solved though.

  264. It's a very great intro tutorial. If you extend it with some functionality required modular structure and authentication you will be the best ;-)

  265. Hi Rob,

    Thanks a lot for this tutorial.
    The reading and understanding how the zend framework works is very easy that you written it.

    Only now i am trying to make my own application, and the basics works fine. But i need some little modification with the fetchRow() methode.

    In youre tutorial you explained that you can echo data with fetchAll() that i understand. But i need to have 1 row back. For the record i will explaine what i mean, my english is not at the best so i hope you understand ;0)

    In just plain php it would like this:

    $sql = "SELECT title,
    artist
    FROM album
    WHERE id = 1";

    and then too echo:
    $result = mysql_fetch_assoc($sql);

    echo $result['title'];
    echo $result['artist'];

    But how doe this work in the zend framework? can you explain that at some time or make a little tutorial from it?

    thanks a lot!

    regards,

    Bart

  266. Bart,

    You need:


    $row = $table->fetchRow('id='.(int)$id);

    Doesn't give you an assoc type output; you need Zend_Db for that.

    Regards,

    Rob…

  267. Hi Rob,

    I have seen the error which i mentioned below i above question answer session.

    Warning: Zend_View::include(./application/views) [function.Zend-View-include]: failed to open stream: Permission denied in C:xampphtdocszf-tutoriallibraryZendView.php on line 46

    Warning: Zend_View::include() [function.include]: Failed opening './application/views' for inclusion (include_path='.;./library/;./application/models') in C:xampphtdocszf-tutoriallibraryZendView.php on line 46

    But still have not solve the problem using the solution u metioned above.

    Please help me in this.

    Thanks & Regards,
    Nilesh Gurav

  268. Hallo Rob,
    I have a class, i want that this class each time be executed. where can i call it.
    this is definition of class:
    class IndexController extends Zend_Controller_Action
    {
    code…
    }

    Thank you.

  269. Nour,

    What do you mean? You could put your code into the init() function for a given controller or you could create a new controller class that all your actual controllers extend and put the code in the init() function of that class.

    Regards,

    Rob…

  270. but i get this error :(Strict Standards: Creating default object from empty value in C:/…) when i do this :
    class IndexController extends Zend_Controller_Action
    {
    function init()
    {
    Zend_Loader::loadClass('pages');
    $this->view->baseUrl = $this->_request->getBaseUrl();
    Zend_Loader::loadClass('CategoryController');
    $CategoryController = new CategoryController();
    $CategoryController->indexAction();

    }

    //get homepage content from pages Table
    function indexAction()
    {

    }

    }

  271. Hi, great tutorial!

    I've just downloaded the latest pdf and the latest zip. The app. work and is all good exept that the stylesheet is not showing. I replaced the lib with the latest release (1.0.3) and the app still is working goog, but no stlesheet???????

    Firebug is giving me this error: MIME type is text/html not text/css

    Where can I fix this????

  272. Hi,

    Excellent tutorial. I've been looking into the Zend Framework for a while now because of it's vast feature set.

    This tutorial is great at explaining the basics which a lot of other tutorials miss out.

    Many thanks
    -Mathew

  273. A tip for the tutorial to make those template files a little bit easier to read is instead of echo'ing everything you can use the following syntax to do the same thing.

    By the way, it's Mathew, one 't'. ;)

  274. Congratulations, the tutorial is very simple and helpful.
    But I still have one problem. I've downloaded the full Zip file of tutorial including ZF1.0.1. The first page is displayed. But, when I try to click on the link 'Add a New Album' or 'Delete' or 'modify Album', IE shows an error page with message 'PAGE NOT FOUND'.
    Could you help me please to undertand the source of the problem and to resolve it.
    Thanks

  275. Zied,

    Your rewrite rules in .htaccess are not working. I suspect that you need to put in AllowOverride All in your httpd.conf file somewhere.

    Regards,

    Rob…

  276. I receive this error and i don't know how to solve it because the table album has a primary key: (i'm usign PDO_Sqlite adapter, there is another way to connect to mysql widthout an adapter?!)

    Fatal error: Uncaught exception 'Zend_Db_Table_Exception' with message 'Primary key column(s) (id) are not columns in this table ()' in /var/www/html/zf-tutorial/library/Zend/Db/Table/Abstract.php:651 Stack trace: #0 /var/www/html/zf-tutorial/library/Zend/Db/Table/Abstract.php(529): Zend_Db_Table_Abstract->_setupPrimaryKey() #1 /var/www/html/zf-tutorial/library/Zend/Db/Table/Abstract.php(264): Zend_Db_Table_Abstract->_setup() #2 /var/www/html/zf-tutorial/application/controllers/IndexController.php(15): Zend_Db_Table_Abstract->__construct() #3 /var/www/html/zf-tutorial/library/Zend/Controller/Action.php(497): IndexController->indexAction() #4 /var/www/html/zf-tutorial/library/Zend/Controller/Dispatcher/Standard.php(237): Zend_Controller_Action->dispatch('indexAction') #5 /var/www/html/zf-tutorial/library/Zend/Controller/Front.php(911): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #6 /var/www/html/zf-tutorial/index.php(42): Zend_Controller_Front-> in /var/www/html/zf-tutorial/library/Zend/Db/Table/Abstract.php on line 651

    Thanks very much, elisa

  277. After beginning first with the ZF-Standard-manual on "Framework MVC" I didn't get the starting-point !
    Then I found your tutorial, it's a real bootstrapped-Tutorial ! After solving the problem to connect to my PGSQL (had php_pgsql.dll instead of php_pdo_pgsql.dll and php_pdo.dll) everything worked fine. Your code really worked by copy and paste from your sheet ! Thanks a lot.
    Niko

  278. Hi Niko,

    I'm glad you found it useful. The idea of the tutorial is that it gets you going and then you have a base from which to experiment.

    In my experience, it's much easier to play when you have something working!

    Regards,

    Rob…

  279. Hi Excellent Tut…

    I have one question, I also notice that i cant get my stylesheet or my js code to load the application is sitting in a subfolder called /zendtut
    but when i goto /zendtut/public/styles/site.css as a test i get a
    exception 'Zend_Controller_Dispatcher_Exception' with message 'Invalid controller specified (public)'

    anyone have any ideas?

  280. Hi! I can solve the problem and i have the tutorial working! thanks for the great tutorial!!!… I want to put in the form to select elements related like Country and State… Can u give me a clue of where i should put the code to access Country and State tables?…

    Thans elisss

  281. Hi Rob,

    Firstly – your tutorial is great. Can't wait for the book.

    Secondly, I tried your tutorial with the latest version of ZF 1.0.3, everything worked except when 'Adding an album' at which point I got the following:

    Fatal error: Uncaught exception 'Zend_Db_Table_Row_Exception' with message 'Specified column "id" is not in the row' ..along with a stack trace.

    I couldn't find the bug so i downloaded your completed tutorial which is bundled with ZF (1.0.1) and It worked fine. However, if I replace the Zend directory bundled with your tutorial with the latest version (i.e. 1.0.3) then the error returns.

    Any ideas?
    Thanks,
    Callan

  282. I was having issues with the .htaccess file from displaying error 500 and css files not being read despite the correct path under xampp for windows. I solved my problems by adding the opening tag and the closing tag. This is how my .htaccess file looks like.

    RewriteEngine on
    RewriteRule !.(js|ico|gif|jpg|png|css)$ index.php

    php_flag magic_quotes_gpc off
    php_flag register_globals off

    Hope this helps!

  283. ""

    RewriteEngine on
    RewriteRule !.(js|ico|gif|jpg|png|css)$ index.php

    php_flag magic_quotes_gpc off
    php_flag register_globals off

    ""

    remove the quotes.

  284. Hi rob,

    Sorry for being such a noob but i was about to start learning PHP Framework and i found your tutorials very helpful to me.

    Now i try to add a different function or module on the album sample you made like i add news, but i get confusing in the controller area as well as in handling it on VIEW, what i did is i just make the same on the Model Part as what you did but on the Controller can you help me on how to work for it, to work those two functions, i hope that you can help me. Thanks a lot :)

  285. Great tutorial!

    thanks very much. really got me started quickly and with the correct set-up.

    It is the only set-up that worked for me on my win 2000 server with XAMPP.

    I had to change the Apache mod_rewrite as it is not enabled with XAMPP by default.

    Thanks a lot!
    G.

  286. Hai Rob,
    I have 2 modules: default and admin

    I use errorHandler for my application. if there is no controller or action the method errorAction of the errorController redirect to frontEnd default/index and I want to check of the current module is admin if it is then i want to redirect to admin/index

    my queston how can i get the current module.
    ————–
    can i use this:
    $this->view->module = $this->getRequest();

  287. Thx for the tutorial. First, I'm somewhat new to ZF, so my apologies for asking what might be obvious to others The ZF Reference shows the following set-up in the Quick Start section of the manaul:

    application/
    controllers/
    IndexController.php
    models/
    views/
    scripts/
    index/
    index.phtml
    helpers/
    filters/
    html/
    .htaccess
    index.php

    with html being the document root. You have a somewhat different set up. The application directory is inside the document root (see below), for example.

    zf-tutorial/
    /application
    /controllers
    /models
    /views
    /filters
    /helpers
    /scripts
    /library
    /public
    /images
    /scripts
    /styles

    Any comments on the pros and cons of each approach would be appreciated.

    Thx, Keith

  288. Hi Keith,

    My directory structure is geared around a shared hosting scenario where you don't have access to any other directory other than the webroot. This was to maximise the breadth of people who could benefit from it.

    Personally, I run all my sites closer to the ZF recommended structure.

    Regards,

    Rob…

  289. The guide was quite good, but I have a small problem with my test site that I created. The CSS does not seem to work and I cannot get images to display. I am using the Zend Framework 1.0.5 and using XAMPP for my desktop server. Beside those problems, I have had no problems.

    Thank you,

    Joe

  290. Hi Rob,

    I have the "same" problem like 416 Vijai.

    Fatal error: Uncaught exception 'Zend_Db_Adapter_Exception' with message 'The mysql driver is not currently installed' in C:Program FilesZendApache2htdocszf-tutoriallibraryZendDbAdapterPdoAbstract.php:104 Stack trace: #0 C:Program FilesZendApache2htdocszf-tutoriallibraryZendDbAdapterAbstract.php(263): Zend_Db_Adapter_Pdo_Abstract->_connect() #1 C:Program FilesZendApache2htdocszf-tutoriallibraryZendDbAdapterPdoAbstract.php(206): Zend_Db_Adapter_Abstract->query('DESCRIBE `album…', Array) #2 C:Program FilesZendApache2htdocszf-tutoriallibraryZendDbAdapterPdoMysql.php(138): Zend_Db_Adapter_Pdo_Abstract->query('DESCRIBE `album…') #3 C:Program FilesZendApache2htdocszf-tutoriallibraryZendDbTableAbstract.php(595): Zend_Db_Adapter_Pdo_Mysql->describeTable('album', NULL) #4 C:Program FilesZendApache2htdocszf-tutoriallibraryZendDbTableAbstract.php(528): Zend_Db_Table_Abstract->_setupMetadata() #5 C:Program FilesZendApache2htdocszf-tutoriallibraryZendDbTableA in C:Program FilesZendApache2htdocszf-tutoriallibraryZendDbAdapterPdoAbstract.php on line 104

    I have 4 php.ini files
    In this is whole configuration:
    C:Program FilesZendCore for Oracleetcphp.ini

    in this:
    C:Program FilesZendCore for Oraclesetupzui_filesphp.ini

    extension_dir = "C:Program FilesZendCore for Oraclesetupzui_files"
    extension = cuwin.dll
    extension = php_ng.dll
    zend_extension = "C:Program FilesZendCore for Oraclelibzendoptimizerphp-5.2.xZendOptimizer.dll"

    in this:
    c: Program FilesZendZendStudio_for_i5OS-5.5.0binphpphp5.ini

    I have:
    extension_dir=C:Program FilesZendZendStudio_for_i5OS-5.5.0binphp5ext
    extension=php_curl.dll
    extension=php_mysql.dll
    extension=php_mysqli.dll
    extension=php_pdo.dll
    extension=php_pgsql.dll
    extension=php_soap.dll
    extension=php_sqlite.dll
    zend_extension_ts=C:Program FilesZendZendStudio_for_i5OS-5.5.0libphp5ZendDebuggerLocal.dll
    zend_debugger.allow_hosts=127.0.0.1/32
    session.save_path=C:Program FilesZendZendStudio_for_i5OS-5.5.0tmp
    include_path = C:Program FilesZendZendStudio_for_i5OS-5.5.0binZendFrameworklibrary;.

    And this – there is nothing in
    C:Program FilesZendZendStudio_for_i5OS-5.5.0binphpdocumentatorphp.ini

    I was try to add to all this php.ini files
    extension=php_pdo.dll
    extension=php_pdo_sqlite.dll
    extension=php_pdo_mysql.dll

    but doesn't work

    System is:
    Zend Core Version 2.5.0
    PHP Version 5.2.5
    Zend Engine Version 2.2.0
    Server API cgi-fcgi
    PHP Configuration File C:Program FilesZendCore for Oracleetcphp.ini

    Web Server
    Server Name localhost
    Server Software Apache/2.2.4 (Win32)
    OS Version Microsoft Windows XP

    Server Configuration

    Server Port 80
    Connection Timeout 300
    Keepalive Timeout 300
    Server Root C:Program FilesZendApache2
    Server Configuration File C:Program FilesZendApache2confhttpd.conf

    Any ideas?
    Thanks,
    rsg

  291. Hi Rob

    Excellent job with the tutorial I finally understand what the framework is and does, however I got to page 16 of your tutorial and hit a problem I hit a few earlier but was able to sort out the problems mainly caused by me misspelling a few things but this one has me stumped after getting through the add album section I am having a problem with the edit album section I can change the contents ok but when I hit the Update button I get the following errors

    ——————————
    Fatal error: Uncaught exception 'Zend_Controller_Action_Exception' with message 'IndexController::20editAction() does not exist and was not trapped in __call()' in C:wampwwwzf-tutoriallibraryZendControllerAction.php:482 Stack trace: #0 [internal function]: Zend_Controller_Action->__call('20editAction', Array) #1 C:wampwwwzf-tutoriallibraryZendControllerAction.php(499): IndexController->20editAction() #2 C:wampwwwzf-tutoriallibraryZendControllerDispatcherStandard.php(242): Zend_Controller_Action->dispatch('20editAction') #3 C:wampwwwzf-tutoriallibraryZendControllerFront.php(929): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #4 C:wampwwwzf-tutorialindex.php(30): Zend_Controller_Front->dispatch() #5 {main} thrown in C:wampwwwzf-tutoriallibraryZendControllerAction.php on line 482
    ———————————–
    any thoughts on this would be greatly appreciated

    Best Regards
    Jon

  292. rsg,

    In your web root, create an info.php file with this in it:

    <php phpinfo();

    View the page with a web browser and it'll tell you which php.ini is in use.

    Regards,

    Rob…

  293. Thank you for fast response, i will try to do something with this file,and I hope that it will work:

    Loaded Configuration File
    C:Program FilesZendCore for Oracleetcphp.ini

    Thanks a lot for this tutorial.

    Thanks,
    rsg

  294. Many thanks for the quick response Rob, it was indeed a rougue space on the very first line of _form.phtml
    it was:
    <form action="baseUrl ?>/index/ action; ?>"method="post">
    and should have been:
    <form action="baseUrl ?>/index/action; ?>"method="post">

    after the trailing slash of /index/

    Now it all works fine

    Thanks again
    Jon

  295. Hi Rob I have finally completed your tutorial and everything works fine, I am a little concerned about the amount of coding involved to actually use this framework I find myself asking this question does it really save time, now, as you are a PHP Developer in your own right, you can answer this does it only save time on really big projects ?

    Kind Regards
    Jon

  296. Hi Jon,

    We find that it does. Mainly because you don't actually change much code between projects. E.g. the bootstrap code we use is the pretty much same. Also we have created a set of extensions to the framework that automate bits and pieces like setting up layouts and forms to our liking.

    After a while, other stuff gets quite quick too, like setting up models, controllers and view scripts etc as you do it the same way each time.

    Regards,

    Rob…

  297. Thanks again for the quick response Rob

    I guess I am still going through a learning curve I would really like to use the framework for my website. at the moment I am actually using (bows head in shame) the joomla cms this was just to speed up deployment of new features and it takes care of the .css for me (I still have to learn more on that subject)but before I did that I originally used dreamweaver for my site and then because it interprets php in its own way (not my way) I ripped the whole site down and re-wrote it using a text editor (in my case Vim) and that took me four days so I think that the zend framework will help but I am not sure how much yet as this is my first look at php frameworks

    Kind Regards

    Jon

  298. *grin*

    Nothing wrong with Joomla – it's a great CMS system. This site uses WordPress for a reason too (laziness on my part)!

    Regards,

    Rob…

  299. Hehe Rob :-)

    So should I concentrate on ZF or go back to hand coding everything ? oh by the way my old site can be found at http://www.euadvantage.com/ows that is the one where I re-wrote it using Vim but kept all the clever bits from DW ;) back in the dim and distant past I learned programming using program code and that is what I enjoy rather than these visual languages(although I must admit I am looking at (sorry for swearing) asp.net and yes I would need to learn VB for that :( (whatever happened to gw basic?)

    Kind Regards
    Jon

  300. :( I tried version 1.0 of this tutorial 2 days ago. Everything worked from the beginning. Finished the tutorial in no time. It all made sense.

    Tried the newest version today. Nothing works :(
    *sigh*… I hate zfw.

  301. Hi Rob,i am grump again :o)

    Now it reads me from data base, but doesn't work any function. Add,delete or edit. If i click on these links its just write:

    Not Found
    The requested URL /zf-tutorial/index/add was not found on this server.

    Ok. i think possibly because add.phtml is into C:Program FilesZendApache2htdocszf-tutorialapplicationviewsscriptsindexadd.phtml

    so i modify:
    <a href="baseUrl; ?>/application/views/scripts/index/add">Add New Album

    now i get:

    Not Found
    The requested URL /zf-tutorial/application/views/scripts/index/add was not found on this server.

    ok it isn't correct. I must do something else.
    Then i look at the end of tutorial:
    Troubleshooting:
    But i have zf-tutorial in root directory.

    Perhaps what with pdo.dll is not ok?

    …It isn't obvious for me this Zend framework,…

  302. It works :o)

    Thank you very much.

    I must delete:
    php_flag magic_quotes_gpc off
    php_flag register_globals off

    from zf-tutorial/.htaccess

    Now it all in program works fine
    Thanks again
    rsg

  303. Hi I have been looking out for such type of tutorial, It has helped me immensiley to understand the basics of Zend Frame Work.If you could help me out as how to implement using Ajax Tutorial and how to make use of Zend_Pdf, it will of great help to me…THANKS IN ADVANCE..Have a Great Day!!

  304. Hello Elisa,
    You solve your problem. I'm happy for you. I would "be more happy" if you would tell us how ? I've got the same problem:
    Uncaught exception 'Zend_Db_Table_Row_Exception' with message 'Specified column "id" is not in the row'

    Regards,
    Charles

  305. Hi Rob,

    Having spent some time thinking about this, I have now spent a little money and downloaded your ebook I think I want to re-construct my site using ZF and I think by just doing that will greatly increase me awareness of how this thing works and should eventually leave me in a position to (relatively speaking) easily add updates and and new features to my site

    With Kind Regards

    Jon

  306. I did this tutorial locally on XAMPP for Mac & am now trying to move it to my shared hosting(Midphase) for testing. I am now receiving this error. Any ideas would be appreciated.

    Fatal error: Uncaught exception 'Zend_Exception' with message 'At least one error occurred including "Zend/Controller/front.php"; see includeErrors property' in /home/bwpnetwo/public_html/dev/library/Zend/Loader.php:300 Stack trace: #0 /home/bwpnetwo/public_html/dev/library/Zend/Loader.php(93): Zend_Loader::_throwIncludeErrors('Zend/Controller…') #1 /home/bwpnetwo/public_html/dev/index.php(8): Zend_Loader::loadClass('Zend_Controller…') #2 {main} thrown in /home/bwpnetwo/public_html/dev/library/Zend/Loader.php on line 300

  307. Ok Hi Brett

    Please do not shoot me down in flames I did notice one thing
    in your path specifiers I noticed /bwpnetwo/
    is that correct or should it be /bwpnetwork/
    just a thought

    with kindest regards
    Jon

  308. Ok Brett I kinda thought that but just wanted to check.

    Normally with any spelling errors you get like 17 pages of errors(well maybe not 17 pages but a lot)

  309. IndexController.php:67

    $id = (int) ….
    // …
    if ($id !== false) //will be always true, so this if should be removed/modified.

  310. Hai Rob.
    Do you want to help me. if i do this:
    class MailerController extends Zend_Controller_Action
    {
    function init()
    {
    }
    function indexAction()
    {
    }
    }
    I get this error: Catchable fatal error: Argument 1 passed to Zend_Controller_Action::__construct() must be an instance of Zend_Controller_Request_Abstract, none given, called in.
    But if i replace function init() by function __construct() i get no error.
    What is better function init() or function __construct().
    Thanks Noury

  311. I suspect you mean the other way around.

    If you override __construct() in your child class, you must give it the same arguments as the parent class and also ensure that you call parent::__construct.

    For this reason, init() is preferred.

    Regards,

    Rob…

  312. Hai Rob sorry for my bad english. But i still get the error do you know what is the problem.

    this is my class definition:

    class Admin_CustomersController extends Zend_Controller_Action
    {

    function init()
    {
    }

    function preDispatch()
    {
    }

    function indexAction()
    {
    }
    .
    .
    .
    .

    }

    if i instantiate the class with
    Zend_Loader::loadClass('Admin_CustomersController');
    $this->Admin_CustomersController = new Admin_CustomersController().<-line 10
    I get this error: Catchable fatal error: Argument 1 passed to Zend_Controller_Action::__construct() must be an instance of Zend_Controller_Request_Abstract, none given, called in…on line 10
    thanks for your help.

  313. because i want to access to loadEmailAction method
    $Emails = $this->Admin_CustomersController->loadEmailsAction();

    Regards
    Noury

  314. Hallo Rob and thanks for your help. I mean if i call and instantiate the class in other class(in this case i call and instantiate the Admin_CustomersController in Admin_NewslettersController)
    then i get the following error:
    Catchable fatal error: Argument 1 passed to Zend_Controller_Action::__construct() must be an instance of Zend_Controller_Request_Abstract, none given, called in
    these are the classes:
    view->baseUrl = $this->_request->getBaseUrl();
    Zend_Loader::loadClass('customers');
    }

    function preDispatch()
    {
    }

    function indexAction()
    {
    }

    function loadCustomersAction()
    {
    }

    function loadCustomerByIdAction($p_ncustomerId)
    {
    }

    function editCustomerAction()
    {
    }

    function loadTodaysCustomersAction()
    {
    }

    function loadLast7DaysCustomersAction()
    {
    }

    function loadLast30DaysCustomersAction()
    {
    }

    function loadEmailsAction()
    {
    }

    function deleteCustomerAction()
    {
    }
    }
    ——————————————-

    view->baseUrl = $this->_request->getBaseUrl();

    Zend_Loader::loadClass('Admin_CustomersController');
    $this->Admin_CustomersController = new Admin_CustomersController();
    }

    function preDispatch()
    {
    }

    function indexAction()
    {
    }

    function loadAction()
    {

    }

    function loadNewsletterByIdAction($p_nnewsletterId)
    {
    }

    function sendAction()
    {
    .
    .
    .

    $this->Admin_CustomersController->loadEmailsAction()
    .
    .
    .
    }

    function loadSubscribersEmailsAction()
    {
    }

    function loadUnsubscribersEmailsAction()
    {
    }

    function addAction()
    {
    }

    function editAction()
    {
    }

    function deleteAction()
    {

    }

    }

    Do you know why i get this terrible error
    Thank you very mutch

  315. But how can i access for example to a methode of Admin_CustomersController in other controller for example Admin_NewslettersController.

    Regards,
    Noury

  316. Noury,

    You shouldn't need to. The functionality you are trying to access should probably be in the Model.

    Regards,

    Rob…

  317. Hi!
    Excellent tutorial!
    I need some help though…
    I would like to use SQLite instead of MySQL database to build the same application described in this tutorial.
    I've installed SQLite on my computer, I've created the same database manually, and I tried to modify the config.ini file, but I couldn't make it work with Zf.
    Can someone tell me, how to modify the config.ini file to make it work?
    Or is there anything else that should be modified?
    Thanks a lot!

  318. Hey Rib, I was wondering, what's the correct way to setup the

    session.save_path

    At this time, it's commented out and I'm receiving a nasty exception when I attempt to invoke

    Zend_Auth::getInstance()->getIdentity();

    Thanks in advance,

    -Conrad

  319. Dear Rob,

    As an hobbyist I've followed your great zf tutorial (getting started with zf). I've done this on a stand-alone xampp setup. Sofar i've got a long way. I get all the views and i'm able to add a new record but somehow i don't be able to edit or delete a record. When i try to edit a record, i get this '<br/>' for artist as for title, when i try to delete a record, it just refreshing the page and nomore then that. I gave it a close look to solve it but…

    For sure i want pass you the code, but i've compare it over and over again with your original version and there aren't any differences to find as only, that i gave the root an other name, just to keep it separate from the original one.

    Then, what i'm doing wrong?
    With regards,
    aad

  320. Hallo Rob,
    I have add a categoryController in your tutorial, I want every time load deze controller that the app be loaded. How can i do this. if i do this in you index controller i get this error.
    ———-
    Catchable fatal error: Argument 1 passed to Zend_Controller_Action::__construct() must be an instance of Zend_Controller_Request_Abstract, none given, called in D:wwwtest_zf_webwinkel-1.0.4-RC1applicationcontrollersIndexController.php on line 11 and defined in D:wwwtest_zf_webwinkel-1.0.4-RC1libraryZendControllerAction.php on line 123

    ————

    class IndexController extends Zend_Controller_Action
    {

    function init()
    {
    Zend_Loader::loadClass('CategoryController');

    $this->CategoryController = new CategoryController();
    $this->view->baseUrl = $this->_request->getBaseUrl();
    }

    //get homepage content from pages Table
    function indexAction()
    {
    $this->CategoryController->indexAction();
    Zend_Loader::loadClass('pages');
    $this->view->title = 'Home';
    $pagesTbl = new pages();
    $where = $pagesTbl->getAdapter()->quoteInto('pagesKey = ?', 'homepage');//where
    $this->view->homepage = $pagesTbl->fetchRow($where);
    }

    }

  321. Dear Rob,
    After putting inn some more persistence, i found the needle in the haystack, now it's working :)

    No need to mentioned here, up to the next steps.

    With regards
    Aad

  322. Hallo Rob, Do you know why i get this error. everything work on my server but on the server of my provider not.

    Erroe
    —————–
    Internal Server Error
    The server encountered an internal error or misconfiguration and was unable to complete your request.
    Please contact the server administrator, support@one.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

    More information about this error may be available in the server error log.

  323. This is an excellent tutorial, Rob, thanks for it. I need to give an advise to those who post comments here. It is a good idea search for the issue they have, before post any question asking for help. What I did was use the Firefox built in searching capabilities to search for the following set of keywords: 'The requested URL http://localhost/zf-tutorial/index/edit/id/1 was not found on this server' and I found a few topics on this matter. After a couple of minutes mi problem was solved, just by reading someone else solution to the same problem.

    So, the next time, you were looking for help, please make sure to search the entire page, before.

  324. I have got the following error .

    Fatal error: Uncaught exception 'Zend_Controller_Action_Exception' with message 'Action "displayaddaccountvendor" does not exist and was not trapped in __call()' in /usr/local/Zend/Core/share/ZendFramework-1.5.2/library/Zend/Controller/Action.php:477 Stack trace: #0 /usr/local/Zend/Core/share/ZendFramework-1.5.2/library/Zend/Controller/Action.php(504): Zend_Controller_Action->__call('displayaddaccou…', Array) #1 /usr/local/Zend/Core/share/ZendFramework-1.5.2/library/Zend/Controller/Dispatcher/Standard.php(293): Zend_Controller_Action->dispatch('displayaddaccou…') #2 /usr/local/Zend/Core/share/ZendFramework-1.5.2/library/Zend/Controller/Front.php(914): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #3 /var/www/int/class/Hb/Util/Control/Front.class(65): Zend_Controller_Front->dispatch() #4 /var/www/int/app/index.php(9): Hb_Util_Control_Front::run() #5 {main} thrown in /usr/local/Zend/Core/share/ZendFramework-1.5.2/library/Zend/Controller/Action.php on line 477

    How can i fix this?

  325. Hi,

    I have only one question:
    Is it possible to load the header and footer files in the index.php file, so they are loaded only once, so when you navigate through the site, only the content is changed, and the header and footer are not refreshed.

    All the best,
    Vali.

    P.S. I like your tutorial, and i saw that you used the same technique like me, loading the header and footer in each html file.

  326. hi
    I already test your code in localhost
    The index.php load ok with the list of albums. But none of the links (add, edit, delete) work for me , message was Page Not Found
    http://localhost/zf-tutorial/index/add

    already set mod_rewrite in httpd.conf uncommented LoadModule rewrite_module modules/mod_rewrite.so and test wiht phpinfo() mod_rewrite is ok can you tell me why ? and Zend Lib already in library ZF-tutorial ?

    but there was error in log apache
    File does not exist: hi
    I already test your code in localhost
    The index.php load ok with the list of albums. But none of the links (add, edit, delete) work for me , message was Page Not Found
    http://localhost:8090/zf-tutorial/index/add

    already set mod_rewrite in httpd.conf uncommented LoadModule rewrite_module modules/mod_rewrite.so and test wiht phpinfo() mod_rewrite is ok can you tell me why ? and Zend Lib already in library ZF-tutorial ?

    but there was error in log apache
    File does not exist: D:/Program Files/Apache Group/Apache2/htdocs/zf-tutorial/index

    and .htaccess file in public directory is empy.

Comments are closed.