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

549 Responses to “Tutorial: Getting Started with the Zend Framework 1.0”

  1. 1 edwood

    Thanks for this great tutorial!

    greets from germany
    ed

  2. 2 Jay Keith

    Great tutorial!

    I've been looking for this, and it has helped me tremendously!

  3. 3 markdbd

    Great work, thanks :D

  4. 4 dedenf

    thank you for the tutorial :)

  5. 5 stefano

    great tutorial, now i want to use zend framework but my hosting have php 4.* :P

    thank you for the tutorial :)

  6. 6 gerardo

    zip file 1.0.1 does not exist :(

  7. 7 Robert

    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!

  8. 8 gerardo

    Linked download is the old PDF (v1.0)
    Download the new PDF (v.1.0.1):
    http://www.akrabat.com/wp-content/uploads/getting-started-with-the-zend-framework_101.pdf

  9. 9 nwrafa

    zip file 1.0.1 does not exist :(

  10. 10 Michael Krenz

    Sorry, but I'm also having trouble with not finding the ZIP… Otherwise, great tutorial!

  11. 11 Rob...

    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.

  12. 12 carlo

    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 programas\apache group\Apache\htdocs\zf_tutorial\library\Zend\Controller\Action.php:92 Stack trace: #0 c:\arquivos de programas\apache group\Apache\htdocs\zf_tutorial\library\Zend\Controller\Action.php(92): Zend_Controller_Action::__call() #1 c:\arquivos de programas\apache group\Apache\htdocs\zf_tutorial\library\Zend\Controller\Action.php(114): IndexController->__call('norouteAction', Array) #2 c:\arquivos de programas\apache group\Apache\htdocs\zf_tutorial\library\Zend\Controller\Dispatcher.php(185): IndexController->run(Object(Zend_Controller_Dispatcher), Object(Zend_Controller_Dispatcher_Token)) #3 c:\arquivos de programas\apache group\Apache\htdocs\zf_tutorial\library\Zend\Controller\Dispatcher.php(136): Zend_Controller_Dispatcher->_dispatch(Object(Zend_Controller_Dispatcher_Token), true) #4 c:\arquivos de programas\apache group\Apache\htd in c:\arquivos de programas\apache group\Apache\htdocs\zf_tutorial\library\Zend\Controller\Action.php on line 92

  13. 13 Rob...

    Carlo,

    Do you have a function called addAction() in your IndexController class?

  14. 14 etng

    Thank you for your excellent tutorial.I'd like to transelate it into Chinese,Can you grant me this privilege?

  15. 15 Rob...

    etng,

    Please feel free to translate to Chinese, as long as you credit me as the original author.

  16. 16 Dan

    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!

  17. 17 Rob...

    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.

  18. 18 Holger Szillat

    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.)

  19. 19 Rob...

    Thanks for that Holger!

  20. 20 Noury

    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

  21. 21 Rob...

    Hi Noury,

    Who knows what the future will bring :)

    Regards,

    Rob…

  22. 22 lamonato

    great job!

  23. 23 Noury

    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');

    }

  24. 24 Rob...

    Noury,

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

  25. 25 Noury

    HOlla ROB How are you?

    Do you have any idee how i use join() in your tutorial.

    Thanks

  26. 26 Jared

    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?

  27. 27 Rob...

    Hi Jared,

    http://framework.zend.com/manual/en/coding-standard.php-file-formatting.html mentions it at the top.

    Regards,

    Rob…

  28. 28 Rob...

    Noury,

    What you do you mean?

    Regards,

    Rob…

  29. 29 Pawel

    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_wamp\www\zf_tutorial\library\Zend\View.php on line 46

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

  30. 30 Pawel

    render($this->actionTemplate); ?>
    its on page 9. Probably script cut part of line so i put spaces now.

  31. 31 Rob...

    Hmm… that's odd as it implies that the actionTemplate variable is empty.

  32. 32 Mark

    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 ?

  33. 33 Noury

    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

  34. 34 kico

    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:\wamp\www\zf-tutorial\library\Zend\Db\Adapter\Pdo\Abstract.php:80 … I didn't put the stack trace

    I'm in page 14 (version 104)

  35. 35 Rob...

    kico,

    You need to enable PHP's MySQL extension in the php.ini file.

    Regards,

    Rob…

  36. 36 kico

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

    Regards

  37. 37 kico

    I'm using ZendStudio 5.1 too

  38. 38 Rob...

    kiko,

    Have you also enabled the PDO MySQL extension?

    Rob…

  39. 39 kico

    I did that too…

    Regards

  40. 40 kico

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

    regards

  41. 41 kico

    problem solved
    i just had to restart windows, i don't know what was it, but its fixed
    thank you

  42. 42 Rob...

    Kico,

    That's very odd. Glad it's solved though!

    Rob…

  43. 43 Dragos Raileanu

    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

  44. 44 Dragos Raileanu

    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

  45. 45 Dragos Raileanu

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

  46. 46 Rob...

    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…

  47. 47 tom

    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…

  48. 48 Dave

    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

  49. 49 Dave

    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

  50. 50 Rob...

    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…

  51. 51 Rob...

    Tom,

    Which page of the tutorial, in which version?

    Regards,

    Rob…

  52. 52 Hasan

    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:\wamp\www\zf_tutt\library\Zend\Db\Adapter\Pdo\Abstract.php:8..etc
    where should I make the changes ??
    Thnx for a great tut.

  53. 53 Rob...

    Hasan,

    You need to ensure that the mysql driver and the PDO mysql driver are enabled in your php.ini.

    Regards,

    Rob…

  54. 54 Hasan

    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:\wamp\Apache2\bin\php.ini i start to work .
    Thnx again ..
    Hasan..

  55. 55 Rob...

    Multiple php.ini files in a system can cause a world of pain. Glad you got it sorted!

    Regards,

    Rob…

  56. 56 John

    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.

  57. 57 Rob...

    John

    Have you tried setting the rewrite base?

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

    Regards,

    Rob…

  58. 58 John

    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.

  59. 59 Justin Hendrickson

    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?

  60. 60 Rob...

    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…

  61. 61 Pádraic Brady

    I still use "deny from all" too ;). Totally unnecessary but it just feels safer, and it does no harm either.

  62. 62 zman

    same error like #12 comment

    error on requested page http://localhost/zf_tutorial/index/add

    solved thus:

    just replace
    $router->setRewriteBase($baseUrl);

    with subfolder tutorial
    like this one
    $router->setRewriteBase('/zf_tutorial');

    """
    Apache/1.3.33 (Win32) PHP/5.1.6

  63. 63 Noury

    he Rob, you promised us to write a login script with zf.

  64. 64 Rob...

    Noury,

    I haven't forgotten!

    Regards,

    Rob…

  65. 65 Matt

    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

  66. 66 Matt

    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.

  67. 67 Matt

    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'],'/'));

  68. 68 Rob...

    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…

  69. 69 Matt

    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!

  70. 70 Dave Cassidy

    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.)

  71. 71 Matt

    Hey Dave,
    I just defined a noRouteAction that gives a 404 error.

  72. 72 Dave Cassidy

    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. :)

  73. 73 Rob...

    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…

  74. 74 Dave Cassidy

    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.

  75. 75 Hasan

    Hi!!
    Does anything of this tutorial changes with the new zf 0.2 release??

    reguards

  76. 76 Rob...

    Yes Hasan,

    That's why I released a new version :)

    Regards,

    Rob…

  77. 77 John

    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

  78. 78 John

    Oops, that code sample did not post very well.

  79. 79 Rob...

    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…

  80. 80 Jason

    When I click on 'Add new album'

    I got this

    http://localhost/zf_tutorial/index/add

    Not Found

    The requested URL /zf_tutorial/index/add was not found on this server.
    Apache/2.0.59 (Win32) PHP/5.1.6 Server at localhost Port 80

    Thanks.

  81. 81 Rob...

    Jason,

    If I was to guess, I'd say that there's a mod_rewrite problem.

    Regards,

    Rob…

  82. 82 christian

    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.

  83. 83 andrew taylor

    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

  84. 84 Rob...

    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…

  85. 85 andrew taylor

    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

  86. 86 Jeremy

    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!

  87. 87 Jason

    Hi Rob,

    How can I solve the mod_rewrite problem?

    BTW, another questions is

    When I type http://mysite/ I can see the right page.
    When I type http://mysite/index.php, nothing showes up.

    Thanks a lot.

    Jason.

  88. 88 Jason

    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.

  89. 89 Jason

    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.

  90. 90 Jason

    I found http://mysite/index works.

    So if index.php can be converted to index somewhere, it will be great.

  91. 91 Rob...

    Jason,

    Are there any error messages in your Apache error log ?

    Regards,

    Rob…

  92. 92 Pooja

    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

  93. 93 Rob...

    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…

  94. 94 Jason

    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-tutorial\library\Zend\Controller\Action.php:92 Stack trace: #0 c:\zf-tutorial\library\Zend\Controller\Action.php(114): Zend_Controller_Action->__call('norouteAction', Array) #1 c:\zf-tutorial\library\Zend\Controller\Dispatcher.php(185): Zend_Controller_Action->run(Object(Zend_Controller_Dispatcher), Object(Zend_Controller_Dispatcher_Token)) #2 c:\zf-tutorial\library\Zend\Controller\Dispatcher.php(136): Zend_Controller_Dispatcher->_dispatch(Object(Zend_Controller_Dispatcher_Token), true) #3 c:\zf-tutorial\library\Zend\Controller\Front.php(254): Zend_Controller_Dispatcher->dispatch(Object(Zend_Controller_Dispatcher_Token)) #4 c:\zf-tutorial\index.php(46): Zend_Controller_Front->dispatch() #5 {main} thrown in c:\zf-tutorial\library\Zend\Controller\Action.php on line 92

  95. 95 Jason

    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:92\nStack 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

  96. 96 Rob...

    Jason,

    Fancy zipping up your project and emailing it to me?

    Regards,

    Rob…

  97. 97 Jason

    Rob,

    I sent it to you.

    Thanks.

  98. 98 R.V.

    The Polish translation links, in fact, to the Italian version and vice versa.

  99. 99 Rob...

    Doh!

    Thanks R.V! I've updated :)

    Regards,

    Rob…

  100. 100 Bruno

    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

  101. 101 Rob...

    Thanks for your kind words, Bruno!

    Regards,

    Rob…

  102. 102 Cookdav

    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

  103. 103 Rob...

    Dave,

    To be hones, I haven't a clue if the current release version is in the tree.

    Regards,

    Rob…

  104. 104 eugene

    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

  105. 105 eugene

    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!

  106. 106 Pooja

    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

  107. 107 Pooja

    looks like i sorted it out

    It was some syntac errrr

    Thnx

  108. 108 Rob...

    Pooja,

    I'm glad you sorted it!

    Regards,

    Rob…

  109. 109 Abdou

    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

  110. 110 Rob...

    Hi Abdou,

    I've started working on a version of the tutorial for v0.6. You can see where I've got to by checking out the svn version at http://svn.akrabat.com/svn/zf-tutorial/trunk/

    Regards,

    Rob…

  111. 111 Abdou

    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 ?

  112. 112 Rob...

    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…

  113. 113 Abdou

    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.

  114. 114 Rob...

    Hi Abdou,

    Did you change __construct() in your index controller to init() as in the svn file ?

    Regards,

    Rob…

  115. 115 Abdou

    Hi Rob,

    The problem is solved now :) i had to change the _construct() of course.

    Thank you a lot…

  116. 116 Rob...

    Great news Abdou!

    Regards,

    Rob…

  117. 117 Ricardo

    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

  118. 118 Riki Risnandar

    Great tutorial.. thanks :) it should be included in Zend Framework documents…
    this tutorial is clear and explain every detail in every line..

  119. 119 Riki Risnandar

    Ricardo, do you define the FooController in FooController.php like this one ?
    class FooController extends Zend_Controller_Action

  120. 120 Will Prater

    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?

  121. 121 Rob...

    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…

  122. 122 anthony

    please help me in this tutorial. im getting error 404 http://localhost/zf-tutorial1/index/add/ but when im in this page http://localhost/zf-tutorial1/ in work. what do you think i must do? thanks in advance..

  123. 123 Rob...

    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…

  124. 124 thony

    Fatal error: Class 'Album' not found in C:\Program Files\xampp\htdocs\zf-tutorial\application\controllers\IndexController.php on line 13
    what would be the solution for this,please help. thanks

  125. 125 Rob...

    Thony,

    At a guess, you haven't set the path to your models/ directory correctly in index.php.

    Regards,

    Rob…

  126. 126 Kyle

    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.

  127. 127 Kyle

    It would seem that I'm having the same problem as Ricardo and anthony.

  128. 128 Kyle

    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

  129. 129 Rob...

    Hi Kyle,

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

    Regards,

    Rob…

  130. 130 Kyle

    It seems more like a bug to me than a feature I need to add back in myself.

  131. 131 Kyle

    While I'm sure Rob has seen it, there's an explanation of why it's this way now here: http://www.nabble.com/forum/ViewPost.jtp?post=7662411&framed=y&skin=16154

    Catching the exception and redirecting was what I had started to do anyway, and if it's good enough for Matt it's good enough for me.

  132. 132 Rob...

    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…

  133. 133 Kyle

    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.

  134. 134 Kyle

    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.

  135. 135 Rob...

    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…

  136. 136 Kyle

    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.

  137. 137 Rob...

    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…

  138. 138 mike

    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

  139. 139 Mile

    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'

  140. 140 Rob...

    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…

  141. 141 ranza

    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

  142. 142 ranza

    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

  143. 143 jim

    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

  144. 144 Rob...

    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…

  145. 145 Rob...

    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…

  146. 146 Sergio

    thank you for the tutorial
    Great work!

  147. 147 giorgio

    Hi Rob,

    problem at page 6 :
    I changed the .htaccess in C:\Programmi\Apache Software Foundation\Apache2.2\htdocs ( 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

  148. 148 Marc

    Any future release of the tutorial for the 0.7.0 release of the ZendFramework?

  149. 149 Rob...

    Good point!

    I'm nearly sure that it works "as is" with 0.7, but I'd better test ;)

    Regards,

    Rob…

  150. 150 San

    Hi,
    Home page is loading fine. When i press on 'Add new album' link (http://localhost/zf-tutorial/index/add)
    "The page cannot be found" error page is coming

    ZF Version : 0.7

  151. 151 San

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

    thanks
    San.

  152. 152 Rob...

    Hi San,

    Glad to hear it!

    Regards,

    Rob…

  153. 153 Themis

    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!

  154. 154 Bagus

    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:\project\oprekzend\library\Zend.php:229 Stack trace: #0 D:\project\oprekzend\library\Zend\Controller\Dispatcher.php(386): Zend::exception('Zend_Controller…', '"index.php" con…') #1 D:\project\oprekzend\library\Zend\Controller\Front.php(725): Zend_Controller_Dispatcher->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #2 D:\project\oprekzend\index.php(16): Zend_Controller_Front->dispatch() #3 {main} thrown in D:\project\oprekzend\library\Zend.php on line 229

    I'm using W2K with IIS and PHP 5.1.4

    thanks..

  155. 155 Rob...

    Hi Baugus,

    What's the URL that you are trying to access?

    Regards,

    Rob…

  156. 156 Bagus

    192.168.0.1/oprekzend/index.php

  157. 157 Rob...

    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…

  158. 158 Bagus

    I finally use setBaseUrl('/oprekzend/index.php')
    and it's done..
    but now when accessing page :
    - http://192.168.0.1/zend/index/add,or
    - http://192.168.0.1/zend/index/edit, or
    - http://192.168.0.1/zend/index/delete

    show page cannot be display at my browser..

    I think this problem because I'm using IIS W2K ?

  159. 159 Rob...

    Hi Bagus,

    You now need to sort out ISAPI_Rewrite. There's more on the wiki at http://framework.zend.com/wiki/x/1Q.

    Alternatively, you should find that URLs of the form http://192.168.0.1/oprekzend/index.php?controller=index&action=edit should work.

    Regards,

    Rob…

  160. 160 glumac

    English version has incorrect link to old 1.2.2.

  161. 161 Rob...

    Thanks glumac!

    Fixed.

    Regards,

    Rob…

  162. 162 Ali

    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

  163. 163 Ali

    Rob,
    Can you please tell me why you didn't approve my posting?
    thanks,
    -Ali

  164. 164 Rob...

    Hi Ali,

    Probably because I pressed the wrong button! I've approved it now. Sorry!

    Regards,

    Rob…

  165. 165 christian

    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

  166. 166 Johannes

    Great work. Looking forward to a 0.8 update ;-)

  167. 167 Glen

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

  168. 168 Rob...

    Glen,

    Where do I use Zend_Controller_RewriteRouter in the tutorial?

    Regards,

    Rob…

  169. 169 Rob...

    christian,

    Missing indexController.php or permissions problem?

    Regards,

    Rob…

  170. 170 christian

    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!

  171. 171 Rob...

    Christian,

    ah! done that too :(

    Regards,

    Rob…

  172. 172 Alan

    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

  173. 173 Rob...

    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…

  174. 174 John

    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.

  175. 175 John

    And then I find this article… doh!

    http://akrabat.com/2007/03/10/goodbye-zendphp/

    Once again, thanks for all your work and help.

  176. 176 Rob...

    Hi John,

    New version of the tutorial is in the works :)

    The latest SVN version of the tutorial code at http://svn.akrabat.com/svn/zf-tutorial/trunk/ works with 0.9 after you fix the typo in Zend/Db/Table/Row/Abstract.php.

    Regards,

    Rob…

  177. 177 José de Menezes

    Hi Rob,

    I tried to use your tutorial, but my ZF is 0.9.0 and it not worked…

    What can I do to make it works??

    Regards,

    José

  178. 178 Zuhair Naqvi

    How bout 0.9.0 Beta MVC tutorial?

  179. 179 Stuart

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

  180. 180 José de Menezes

    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:\www\projeto\lib\Zend\Controller\Response\Abstract.php:240 Stack trace: #0 D:\www\projeto\lib\Zend\Controller\Response\Abstract.php(125): Zend_Controller_Response_Abstract->canSendHeaders(true) #1 D:\www\projeto\lib\Zend\Controller\Action.php(607): Zend_Controller_Response_Abstract->setRedirect('/projeto/', 302) #2 D:\www\projeto\application\controllers\IndexController.php(45): Zend_Controller_Action->_redirect('/') #3 D:\www\projeto\lib\Zend\Controller\Action.php(392): IndexController->addAction() #4 D:\www\projeto\lib\Zend\Controller\Dispatcher\Standard.php(211): Zend_Controller_Action->dispatch('addAction') #5 D:\www\projeto\lib\Zend\Controller\Front.php(750): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #6 D:\www\projeto\index.php(44): Zend_Controller_Front->dispatch() #7 {main} thrown in D:\www\projeto\lib\Zend\Controller\Response\Abstract.php on line 240

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

  181. 181 José de Menezes

    How to get the source code??? how to use these SVN stuff?

  182. 182 Scott

    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?

  183. 183 Stuart

    Jose, first get a copy of subversion (svn). You can get Rob's latest code with the command:

    svn co http://svn.akrabat.com/svn/zf-tutorial/branches/1.2/

  184. 184 Rob...

    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…

  185. 185 Brian

    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).

  186. 186 Scott

    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!

  187. 187 Rob...

    Scott,

    Great - I'm glad 27 fixed that one!.

    With any luck 28 fixes the include path issue.

    Regards,

    Rob…

  188. 188 John

    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.

  189. 189 rob

    The best Tutorial. This should be included in zend as the official tutorial.

  190. 190 John Lawson

    Great tutorial!
    I would like to report a minor typo - the hyperlink at the top of page 5 refers to http://localhost/zf_tutorial/
    instead of
    http://localhost/zf-tutorial/

    Regards

  191. 191 Pieter

    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.

  192. 192 Jeff

    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.

  193. 193 Rob...

    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…

  194. 194 Jeff

    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($fil