Tutorial: Getting Started with Zend Framework 1.5

Tutorial-Screenshot.jpg
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.5.0 of the Zend Framework. It stands a very good chance of working with later versions. It will not work on any version prior to version 1.5.0.
Also, If you are getting 404 errors when going to any page other than the home page, please make sure that you have set AllowOverride to All in your Apache configuration.

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

Translations

French by Guillaume Rossolini: http://g-rossolini.developpez.com/tutoriels/php/zend-framework/debuter/
Czech by Petr Parimucha: http://weblog.pari.cz/293/zaciname-se-zend-framework-15
Portuguese (BR) by José Luciano Calazans Jr.: Iniciando_com_Zend_Framework_1.5.pdf

Code

The associated code is available:

Further reading

Once you have finished this tutorial, Pádraic Brady is in the process of writing a very comprehensive blog tutorial that is well worth going through. Or just buy the book!

Previous versions of this tutorial

The original tutorial for Zend Framework 1.0 is still available, along with the translations for it.

Changelog

1.5.2
Use a screenshot for the directory layout.
1.5.1
Fixed minor mistakes found by Jason Qi and Źmicier.
1.5.0
Significant revision to take advantage of Zend Framework 1.5
1.4.0
Updates to support version 1.0.0. RC1 of the Zend Framework.
1.3.0
Significant reworking to support version 0.9 of the Zend Framework.
1.2.0
Updated tutorial for version 0.6 of the Zend Framework.
1.1.0
Updated tutorial for version 0.2 of the Zend Framework.
1.0
Original version

140 Responses to “Tutorial: Getting Started with Zend Framework 1.5”

  1. 1 WIL

    Hallo Rob,
    I use your Tutorial: Getting Started with Zend Framework 1.5 on my local server works very good and if i load it on the server of my provider i get this error:
    ———–
    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.

    —————
    http://www.dynascript.nl/zf-tutorial/public/index.php

    Regards,
    Wil

  2. 2 Rob...

    Wil,

    I think you are going to have to see the logs to work out what's going on.

    Regards,

    Rob…

  3. 3 WIL

    I have sent mail to support.one.com and they say their server don't support zend framework. but their server support php5.2.5.

  4. 4 Raz

    Hello Rob…
    just yesterday began with the old tutorial and i was thinking that it's been some time since 2006 :P. Anyway I'm new to zf and you're giving me a big hand with your work. Thanks.
    p.s. i need to integrate ext JS with zend can you please give me a start point?
    pp.s. thanks again

  5. 5 Rob...

    Hi Raz,

    The old tutorial had been pretty well debugged by version 1.4.5, so didn't need much in the way of updating regularly.

    However Zend Framework 1.5 brings some very useful new features with Zend_Layout and Zend_Form that a new version was most certainly required in order to understand how useful ZF is.

    Regards,

    Rob..

  6. 6 Mark

    WIL,

    I had the same problem, its due to the .htaccess file. Here is the response that worked for me. The log file reads: "Invalid command 'RewriteEngine', perhaps mis-spelled or defined by a module not included in the server configuration."

    The solution:
    "It sounds like you don't have mod_rewrite loaded.

    If it's your server, open the httpd.conf file and look for these lines:

    #LoadModule rewrite_module modules/mod_rewrite.so
    #AddModule mod_rewrite.c

    If you see them, simply remove the # from the beginning and then save the file. If you don't see them, put them in there, without the #, of course.

    You will need to restart Apache for the change to take place."

    You should read what it says in the log files.

    "

  7. 7 Mark

    Also, this tutorial was great. Got me started on the right direction and understanding how the MVC system works. I love it how you don't need to name any files, you see no file extensions when using the site, it's mad.

  8. 8 WIL

    Hallo Rob, could you help me with this issue. If i go to this url http://www.dynascript.nl/public/index.php then everything works good but i want if the user go to this http://www.dynascript.nl then the site works too.
    Regards,
    Wil

  9. 9 WIL

    O sorry i mean if the user go to this http://www.dynascript.nl then i get http error 403.

  10. 10 Turist

    Thanks Rob, hope you'll upgrade the Zend_Auth tutorial ;)

  11. 11 Rob...

    Wil,

    You'll need to move index.php to the root.

    Regards,

    Rob…

  12. 12 Rob...

    Mark,

    Glad you found it useful :)

    Regards,

    Rob…

  13. 13 Rob...

    Turist,

    All in good time… I'm a bit snowed under at the moment though!

    Regards,

    Rob…

  14. 14 Отдых

    After install tutorial and open in browser i have err, what is it? help me pls, mysql in other php applications good work.

    Fatal error: Uncaught exception 'Zend_Db_Adapter_Exception' with message 'The mysql driver is not currently installed' in C:\www\rasprodagafront\library\Zend\Db\Adapter\Pdo\Abstract.php:104 Stack trace: #0 C:\www\rasprodagafront\library\Zend\Db\Adapter\Abstract.php(390): Zend_Db_Adapter_Pdo_Abstract->_connect() #1 C:\www\rasprodagafront\library\Zend\Db\Adapter\Pdo\Abstract.php(206): Zend_Db_Adapter_Abstract->query('DESCRIBE 'album…', Array) #2 C:\www\rasprodagafront\library\Zend\Db\Adapter\Pdo\Mysql.php(137): Zend_Db_Adapter_Pdo_Abstract->query('DESCRIBE 'album…') #3 C:\www\rasprodagafront\library\Zend\Db\Table\Abstract.php(605): Zend_Db_Adapter_Pdo_Mysql->describeTable('albums', NULL) #4 C:\www\rasprodagafront\library\Zend\Db\Table\Abstract.php(534): Zend_Db_Table_Abstract->_setupMetadata() #5 C:\www\rasprodagafront\library\Zend\Db\Table\Abstract.php(269): Zend_Db_Table_Abstract->_setup() #6 C:\www\rasprodagafront\application\controllers\IndexController.php(8): Zend_Db_Table_Abstract->__construct() #7 C:\www\rasproda in C:\www\rasprodagafront\library\Zend\Db\Adapter\Pdo\Abstract.php on line 104

  15. 15 Rob...

    От'ых,

    Try installing the PDO and PDO_MYSQL PHP extensions.

    Regards,

    Rob…

  16. 16 Mister Olympia

    Rob thank you.

    May be you know, why if i click at any link in that script(tutorial), browser open that page "Object not found Error 404″.

  17. 17 Rob...

    Mister Olympia,

    Two choices:
    1. Your .htaccess isn't being read
    2. mod_rewrite needs enabling in httpd.conf

    Regards,

    Rob…

  18. 18 Wil Sinclair

    Wow! Someone else named Wil who spells it with one 'l'. So this is what it sounds like. . . when doves cry. (see 'Lemons of Troy' episode of the Simpons).

    ,Wil

  19. 19 WIL

    Hallo rob thanks for you reaction, I have a problem, your tutorial works very good.Now i want to load an other controllerclass (categoryController) with the indexcontroller thus both at the same time. I want to display categoryController (indexAction) as a menu on the top en the indexcontroller (indexAction) on the body of the website.
    How can i solve that
    Regards,
    Wil

  20. 20 Rob...

    Wil,

    You need to use the ActionStack. Have a look at my Simple Zend_Layout Example post for ideas.

    Regards,

    Rob…

  21. 21 Rob...

    Wil Sinclair,

    It's not that uncommon over this side of the pond. At least, I know a couple of guys who use the single l version :)

    Regards,

    Rob…

  22. 22 Rob...

    Wil,

    Hmm… not that entry!

    I was thinking of chapter 4 of Zend Framework in Action!

    Sorry,

    Rob…

  23. 23 WIL

    I have bought jesterday your book, I have received pdf and in September 2008 (est.) i wil receive print book, Ok i wil read right now chapter 4.
    Thanks

  24. 24 noury

    Hai Rob,
    Could you tell me
    How i can execute an action of classcontroller within an other controller.
    For examle i want to execute this function messagesAction($num) in other controller.
    Note: messageAction have a parameter.
    Thanks

  25. 25 Rob...

    noury,

    _forward().

    Regards,

    Rob…

  26. 26 noury

    I have an action with a parameter. how can i pass that parameter to my acion with _forward.for example: messagesAction($num);
    thanks

  27. 27 Rob...

    noury,

    $this->setParam(num, $num);

    Regards,

    Rob…

  28. 28 monika

    Hi, I'm a new to Zend and PHP, and trying to learn it from your tutorial. Currently I'm using XAMPP and downloaded your tutorial. I have configured the application/config file to access MySQL and created the table and entries with the exact same names. But when running the webapp I got the following error:

    Fatal error: Uncaught exception 'Zend_Db_Statement_Exception' with message 'SQLSTATE[42S02]: Base table or view not found: 1146 Table 'zftest.albums' doesn't exist'

    I see the albums coming from the model/Albums.php. Why it can not map it?

    I have no idea what else needs to be modified to make it run… Any suggestion would be really appreciated.
    Thank you.
    Monika

  29. 29 Rob...

    Monika,

    You haven't created the database table within MySQL.

    Regards,

    Rob…

  30. 30 Falcon

    Hi there, first of all, your tutorial is great. I have a little problem though: when I submit the changes, the _redirec('/') part does not work. I get this error message:

    Cannot send headers; headers already sent…

    Now what? :)

    Thanks

  31. 31 Rob...

    Falcon,

    Have you googled?

    Regards,

    Rob…

  32. 32 Falcon

    Rob, sure I did, didn't want to look totally noob :) Despite my efforts, I look. So, all I have found is that nothing should be prior to the header information that is redirecting, and this I have already known. What I don't know is how this all works if I use Zend. Am a bit confused, though I'm trying to figure it out.

    Respect
    Falcon

  33. 33 Dennis Fogg

    Please see "Naming Recommendation for Controllers, Actions, and URLs using zend_controller" at http://www.nabble.com/Re%3A-Naming-Recommendation-for-Controllers%2C-Actions%2C-and-URLs-using-zend_controller-p16366498.html
    where the zend developer says:

    Your controllers and actions can have camelCasing to accomodate multiple words

    This is a clarification on some of the advice that you have in your tutorial.

  34. 34 Rob...

    Dennis,

    Whilst you are correct that it is possible to use camel casing in action names, make sure you have read and understood the note on http://framework.zend.com/manual/en/zend.controller.basics.html:

    "Since humans are notoriously inconsistent at maintaining case sensitivity when typing links, Zend Framework actually normalizes path information to lowercase. This, of course, will affect how you name your controller and actions… or refer to them in links.
    If you wish to have your controller class or action method name have multiple CamelCasedWords, you will need to separate those words on the url with either a '-' or '.' (though you can configure the character used).
    As an example, if you were going to the action in FooBarController::bazBatAction(), you'd refer to it on the url as /foo-bar/baz-bat or /foo.bar/baz.bat."

    Also, camel cased action names were the biggest cause of upgrade problems from 1.0 to 1.5. So much so that it is mentioned in the migration notes here: http://framework.zend.com/manual/en/zend.controller.migration.html#zend.controller.migration.fromoneohtoonefive.

    The upshot is that camel casing action names is fine as long as you use hyphens in your URLs and view script filenames.

    Regards,

    Rob…

  35. 35 Dennis Fogg

    Rob,

    Thanks for the pointer to the docs on camelCase. Casing is discussing in multiple places and I missed that one.

    BTW, your link has an extra character at the end (:) so the link should be http://framework.zend.com/manual/en/zend.controller.basics.html

  36. 36 Rob...

    Thanks Dennis,

    Don't you just hate auto-linking at times?!

    Rob…

  37. 37 Kyia

    Hi,Rob

    The index page is work properly, but
    the url: http://http://localhost/zf_tutorial-150-with-zf/public/index/add shows:
    The requested URL /zf_tutorial-150-with-zf/public/index/add was not found on this server.

  38. 38 Nooooooooooob

    Pretty much the same problem as kyia it gives me the classic err that it cannot find the add controller though the controller is good and index works. Im a bit confused on what i should put in add.php and edit.php

  39. 39 Nooooooooooob

    Oh and by the way stuff never works when i was your version of .htaccess but if i use the default zend router from the doc i get index working help a brother out

  40. 40 Nooooooooooob

    Scratch that i got it working but i'd still like to know why .htaccess doesnt work

  41. 41 PhrosTT

    ATTENTION ALL:

    v.1.5.1 of this tutorial has a serious typo!

    The directory structure should have application, public, & library all within the same level. The should all be in zf-tutorial.

    public and library DO NOT GO INSIDE THE APPLICATION FOLDER!

    It should be:

    zf-tutorial
    -application
    –controllers
    –models
    –views
    -library
    -public
    –css
    –images
    –js

  42. 42 PhrosTT

    To restate for better visibility:

    The directory structure should be such that you have:

    zf-tutorial/application/controllers/IndexController.php
    zf-tutorial/application/models
    zf-tutorial/application/views
    zf-tutorial/application/views/scripts/index/add.phtml
    zf-tutorial/library/Zend
    zf-tutorial/public/css
    zf-tutorial/public/images
    zf-tutorial/public/js
    zf-tutorial/public/index.php
    zf-tutorial/public/.htaccess

  43. 43 Rob...

    I've been struggling with the indentation of the folders. I should probably do a screenshot!

    Rob…

  44. 44 eko

    dear sir,

    i'm is student from indonesia and i'm is beginner in php. i have project from my school, how to connect zf with 2 different db. for master data i'm using ms. sql server and save data to mysql.

    thx's for your help.
    eko

  45. 45 Jevylux

    Hi Rob, thanks for this upgraded tutorial.
    It's a great help for me as a ZF Newbie.
    I however have a problem with the inclusion of the css stylesheet file in my own application, which I chaged to use layout as of today.

    The Baseurl helper seems to return nothing.
    It looks as it is called, but the getBaseUrl returns nothing.
    Here is the code of BaseUrl.php
    getBaseUrl();
    }
    }
    ?>

    What went wrong ?

  46. 46 Neo May

    Rob, I open up my IE, I am getting:

    set('config', $config); // setup database $db = Zend_Db::factory($config->db); Zend_Db_Table::setDefaultAdapter($db); // setup controller $frontController = Zend_Controller_Front::getInstance(); $frontController->throwExceptions(true); $frontController->setControllerDirectory('../application/controllers'); Zend_Layout::startMvc(array('layoutPath'=>'../application/layouts')); // run! $frontController->dispatch();

    New to PHP, please help!

  47. 47 Alex

    Hi Rob.

    Thank you very much for this great tutorial. It was very helpful for me as a beginner in developing with the Zend Framework. Big THX. Keep it up!

  48. 48 Paris

    Hi Rob,

    First of all, thanks for all this great tutorials!

    I was wondering why you don't put the layout directory in /application/views? Maybe you have a good reason, hope I'm not been imprudent lol.

  49. 49 FatCore

    Wow, i'm impressed. This is the best introduction tutorial to a MVC framework i've ever seen. Most framework tutorials don't give fully information to get started like how to use layouts (or partials) to prevent duplicate coding. Thanks and keep up the good work, i'll buy your book.

  50. 50 Ina

    Thanks. Quick, easy to understand, just the best ZF newbie tutorial I've seen so far!

  51. 51 ptoom

    I've gotten cake, symphony, and ap3 skeleton to "just work". Can't get zend to "just work". Can't get your tutorial files to work (1.0,1.3, nor 1.41)…. I had a list of the problems I've been having … but I'll try 1.5.2 just to be sure….

    …do you think I'm mentally retarded? I mean, I've been trying to get zfw to work on my localhost since…gosh, since framework.zend.com went live! Haven't gotten it to work yet…haven't gotten your tutorial files to work either. Am I stupid. Somebody fill me in. wtf?

  52. 52 ptoom

    my setup and my problems

    http://localhost/zfw/ is where I put your files
    When I go to this address I get:
    Forbidden
    You don't have permission to access /zfw/public/ on this server.

    So I comment out the rewrite lines of the .htaccess file in zfw/public

    Now I get a fatal error and stack trace because I don't have PDO.
    (I don't have pdo because I try to match our live server which also doesn't have PDO and won't be upgraded for another year or 2)
    So I edit the config file and change the db adapter to MYSQLI.

    I recreate the zftest database, album table, user rob with password 123456.

    I'm pretty sure with version 1.41 of your tutorial my problem was with the Album model class or with the database connection itself. But I couldn't figure out how to troubleshoot the album object. I'd usually start by var_dump-ing or print_r-ing the object but somewhere in the creation of the "new Album" the app would die without generating any kind of error (display errors was on and error reporting was set to E_ALL)

    Now I get a different fatal error:
    Fatal error: Uncaught exception 'Zend_Db_Adapter_Mysqli_Exception' with message 'The Mysqli extension is required for this adapter but the extension is not loaded' in W:\www\zfw\library\Zend\Db\Adapter\Mysqli.php:280

    So I try changing the adapter to MYSQL:
    Fatal error: Uncaught exception 'Zend_Exception' with message 'File "Zend\Db\Adapter\Mysql.php" was loaded but class "Zend_Db_Adapter_Mysql" was not found in the file' in W:\www\zfw\library\Zend\Loader.php:88

    Took a look in Zend\Db\Adapter\ and there actually is not a file named Mysql.php

    So I don't have pdo or mysqli and zfw doesn't want to use mysql_ …and now I don't know where to go from here.

  53. 53 Rob...

    ptoom,

    You have to have either the mysqli or pdo extensions installed.

    Regards,

    Rob…

  54. 54 JhepunK

    Hey Buddy, this tutorial is great. Thank you, terima kasih, gracias, whatever lah it's the same point.

  55. 55 walter

    xHTML results…

    Your wonderful example does not create xHTML. I found this bit …

    $viewRenderer->view->doctype('XHTML1_STRICT');

    But i have no idea where to place in with the structure of your example code.

    Can you give guidance?

    Thx

  56. 56 walter

    on "$frontController->setBaseUrl ();"

    why can't I place a full URL [http://mydomain.com/path/] in this property?

    When I do, none of the links within this demo works. They look right when I view source, but they don't go anywhere.

    Walter

  57. 57 Rob...

    Walter,

    The BaseUrl is the bit after the server name. In this case, "/path"

    Regards,

    Rob…

  58. 58 walter

    Rob, yes, I gathered that; then how do I get the "server name" into the paths on the generated links?

  59. 59 Mattias

    Why do are my menu links set to visited while using this tutorial?

    above the content div i have:

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

    <a href="url(array('controller'=>'index','action'=>'items'));?>"> Varor

    <a href="url(array('controller'=>'index','action'=>'info'));?>"> Info

  60. 60 Mattias

    that ctrl v was not so successfull :(

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

    <a href="url(array('controller'
    =>'index','action'=>'items'));?>"> Varor

    <a href="url(array('controller'
    =>'index','action'=>'info'));?>"> Info

  61. 61 Mattias

    omg!

    ok i describe the setup with words-

    one headerwrapper div with an header div inside.

    the above mentioned links all have a menu div each.

  62. 62 guenti

    Hi Rob,

    I will translating your tutorial to german and publishing in my blog. Is it okay?

  63. 63 Rob...

    guenti,

    Sure!

    Regards,

    Rob…

  64. 64 guenti

    Rob,

    fine! This tutorial is one of the best that I've found in the www, and it's up to date. If I have published the german version, I will communicate it to you.

  65. 65 Felix Jacobi

    If you're having problems with the Zend_View_Helper_BaseUrl Class because it returns nothing and you're running this Tutorial in a VHost or Rootdirectory of your Apache try it that way:

    setBaseUrl('.');
    return $zcf->getBaseUrl();
    }
    }
    ?>

  66. 66 TedInAK

    Excellent tutorial! I'm new to ZF and been playing around with it for the last week or so. Found a bug in your BaseUrl.php, though. If you include "index.php" in your browser's address bar, e.g., http://example.com/zf_tutorial/index.php, then baseUrl() returns "/zf_tutorial/index.php" which breaks the usage of it, notably in:

    <link rel="stylesheet" type="text/css" media="screen" href="baseUrl();?>/css/site.css" />

    which returns

    Here's my fix:

    function baseUrl()
    {
    $baseUrl = Zend_Controller_Front::getInstance()->getBaseUrl();
    return str_replace('/index.php', ", $baseUrl);
    }

  67. 67 TedInAK

    Whoops…that got broken. Lemme try again:

    Excellent tutorial! I'm new to ZF and been playing around with it for the last week or so. Found a bug in your BaseUrl.php, though. If you include "index.php" in your browser's address bar, e.g., http://example.com/zf_tutorial/index.php, then baseUrl() returns "/zf_tutorial/index.php" which breaks the usage of it, notably in:

    <link rel="stylesheet" type="text/css" media="screen" href="baseUrl();?>/css/site.css" />

    which returns

    Here's my fix:

    function baseUrl()
    {
    $baseUrl = Zend_Controller_Front::getInstance()->getBaseUrl();
    return str_replace('/index.php', ", $baseUrl);
    }

  68. 68 mdrisser

    I'm having the same problem as Kyia, localhost/zf-tutorial/ works just fine, but localhost/zf-tutorial/index/add doesn't, all I get is a 404 not found error.

    I've checked and rechecked the .htaccess file, checked the httpd.conf (mod_rewrite is installed), there's nothing in the logs that indicates why it's not working. Any suggestions?

  69. 69 Rob...

    mdrisser,

    AllowOverride is not set to All

    Regards,

    Rob…

  70. 70 Trinath

    Hi ,

    I have followed the ZF tutorial and implemented it ..

    Iam able to see the index page but unable to see other pages ..

    Like I able to see http://localhost/gen gives me the index page

    but http://localhost/gen/index/add is showing me 404 error page not found .. though I have the .phtml file and addAction() in IndexController.php file

    please help me in this regard ..

    -
    Trinath

  71. 71 Garra

    Thanks
    But how can i install pdo extensions

  72. 72 alitrix

    @Trinath, did you check your apache config?

    Search for something like this:

    Options FollowSymLinks
    AllowOverride None

    Make it:
    AllowOverride All

  73. 73 SuperVlao

    Pretty nice :)

  74. 74 jegan

    very good tutorial for the zend framework beginners like me… i searched many ,but find this is best

  75. 75 Fadel

    Pretty nice, thank you

  76. 76 Onur Özgür ÖZKAN

    Dear Rob,

    This is the best article which i have been seen over ZF beginners. I translate it in Turkish. You can find http://www.onurozgurozkan.org/2008/05/17/zend-frameworke-giris/

    Best Regards.

  77. 77 jharder

    Hi Rob,

    I've tried to get your tutorial to work on my local machine, but I'm hitting the same 404 errors that others have reported. Your complete sample works just fine, and I've combed through my httpd.conf file and set every AllowOverride I can find to All.

    What am I missing?

  78. 78 firecall

    Great PDF tut. Thanks :)

    Typo: page 7:
    "That is, the view script rendered is
    views/scripts/{controller name}/{action_name}.phtml and the rendered
    contents are append it to the Response object’s body."

    should read "… appended to…" I guess :)

  79. 79 firecall

    Bottom of page 8:

    "Testing each controller/action by navigating the urls shown earlier should display the four
    titles within the web browser. "

    It wasnt totaly clear that the urls need to be something like:
    localhost/index/add

    etc…

    I tried localhost/add which didnt work :)

  80. 80 dogggg

    Having problems getting bootstrapper to work. My error in apache is

    .htaccess: Invalid command 'php_flag', perhaps misspelled or defined by a module not included in the server configuration

    I'm not sure what to do with mod_php.

  81. 81 dogggg

    Nevermind, I found a solution

    https://www.hostingclientsupport.com/index.php?_m=knowledgebase&_a=viewarticle&kbarticleid=34

  82. 82 firecall

    Typo, top of page 10:

    "…we require form
    the request object."

    should be 'from'.

  83. 83 firecall

    Hint for anyone that gets the "Cannot send headers.." error message.

    Remove any white space before the <?php tags!

    I didnt know about that and got the error :)

  84. 84 greggo

    Hi, Im on a Mac, using Leopard and I get the error "Fatal error: Uncaught exception 'Zend_Db_Adapter_Exception' with message 'The mysql driver is not currently installed' in /Library/WebServer/Documents/zend/library/Zend/Db/Adapter/Pdo/Abstract.php:104 Stack trace: #0 /Library/WebServer/Documents/zend/library/Zend/Db/Adapter/Abstract.php(390): Zend_Db_Adapter_Pdo_Abstract->_connect() #1 /Library/WebServer/Documents/zend/library/Zend/Db/Adapter/Pdo/Abstract.php(206): Zend_Db_Adapter_Abstract->query('DESCRIBE 'album…', Array) #2 /Library/WebServer/Documents/zend/library/Zend/Db/Adapter/Pdo/Mysql.php(137): Zend_Db_Adapter_Pdo_Abstract->query('DESCRIBE 'album…') #3 /Library/WebServer/Documents/zend/library/Zend/Db/Table/Abstract.php(605): Zend_Db_Adapter_Pdo_Mysql->describeTable('albums', NULL) #4 /Library/WebServer/Documents/zend/library/Zend/Db/Table/Abstract.php(534): Zend_Db_Table_Abstract->_setupMetadata() #5 /Library/WebServer/Documents/zend/library/Zend/Db/Table/Abstract.php(269): Zend_Db_Table_Abstract->_setup() #6 /Library/WebServer/Documents/zend/application/cont in /Library/WebServer/Documents/zend/library/Zend/Db/Adapter/Pdo/Abstract.php on line 104″.
    I installed the pdo.so and pdo_mysql.so files, but the stock Mac Leopard PHP won't load them. When I run "php -m | grep -i pdo" I get "PHP Warning: PHP Startup: Unable to load dynamic library './pdo.so' - (null) in Unknown on line 0
    PHP Warning: PHP Startup: Unable to load dynamic library './pdo_mysql.so' - (null) in Unknown on line 0
    PDO
    pdo_sqlite". Ive read that PHP in Leopard had dynamic extention loading disabled, but not sure how reliable that is.
    Is there a workaround?

  85. 85 greg

    Ok, for all you Mac Leopard users like me who have had this issue, the workaround is to not even bother with the pdo_mysql. Leopard's PHP5 comes with MYSQLI already set up, so to get your db connection you have to change the config.ini in this tutorial. You DO NOT need a different install of PHP. Go to application/config.ini and change db.adapter = PDO_MYSQL to be db.adapter = MYSQLI. Works like a charm then.

  86. 86 Rob...

    Hi greg,

    That works great until you need GD :)

    Rob…

  87. 87 K

    Thats a great tutorial, I've been avoiding using Zend since theres a lack of simple getting started material, but this has convinced me to give it a try.

  88. 88 Snowcore

    Really nice post! Thanks!

  89. 89 Kevin

    Thanks for the great tut! One thing tho…

    Who uses 'id' for their primary key? Typically it would be 'user_id' or 'product_id'. You mention that the default for Zend_Db_Abstract is to look for 'id' but I think it would be much more helpful if your tutorial actually used a primary key other than the default. I've been all over looking for how to do this and I can't seem to get around it. I've added:
    protected $_primary = 'album_id';
    to the Albums.php class/model but it's as though it is simply ignored. Any help would be greatly appreciated!!! Thanks again, this tutorial got me up and going with ZF.

  90. 90 Lubos Lavicka

    GREAT, GREAT, GREAT!!! Thanks very much! Simple, straightforward.

  91. 91 Martijn

    for some reason the only way i can get the models to work is to manually include them like this.

    include('../application/models/Albums.php');
    include('../application/models/AlbumForm.php');

    Any reason for this not working?

    Any help is appreciated

  92. 92 Rob...

    Hi Martijn,

    At a guess, your models directory isn't on your php_include path.

    Regards,

    Rob…

  93. 93 Martijn

    Anyway to fix this? Or check..

  94. 94 Dan

    Rob, thanks for the tutorial - it has really helped.

    The problem I'm having is that with the code:

    $row = $courses->fetchRow('ID='.$id);
    $row->TITLE = $form->getValue('TITLE');
    $row->save();

    I get a "Call to undefined method stdClass::save()" fatal error, but http://framework.zend.com/manual/en/zend.db.table.row.html says the fetchRow() method returns an object of type Zend_Db_Table_row, so this code should be fine, right?

    Any advice on this appreciated.

  95. 95 Elias

    Hi,

    for me it's not clear when I must use the Zend_Form and when I can create the form in the view script. For instance,why did you use zend_Form for the pages "add" and "edit", but didn't for "delete" page?

    thanks!

  96. 96 Rob...

    Elias,

    It's up to you :) I show both ways in the tutorial.

    Rob…

  97. 97 koushika

    Dear rob,
    i am student and i am learning php, for which i downloaded this application. tried to deploy finally when i tried running using :

    http://localhost/zf_tutorial/public/

    i got the following error please help me. i am doing my academic project too in jsp with zend frame work. i wish your guidance. thank you

    Fatal error: Uncaught exception 'Zend_Db_Adapter_Exception' with message 'SQLSTATE[28000] [1045] Access denied for user 'koushika'@'localhost' (using password: YES)' in C:\wamp\www\zf_tutorial\library\Zend\Db\Adapter\Pdo\Abstract.php:131 Stack trace: #0 C:\wamp\www\zf_tutorial\library\Zend\Db\Adapter\Abstract.php(390): Zend_Db_Adapter_Pdo_Abstract->_connect() #1 C:\wamp\www\zf_tutorial\library\Zend\Db\Adapter\Pdo\Abstract.php(206): Zend_Db_Adapter_Abstract->query('DESCRIBE 'album…', Array) #2 C:\wamp\www\zf_tutorial\library\Zend\Db\Adapter\Pdo\Mysql.php(137): Zend_Db_Adapter_Pdo_Abstract->query('DESCRIBE 'album…') #3 C:\wamp\www\zf_tutorial\library\Zend\Db\Table\Abstract.php(605): Zend_Db_Adapter_Pdo_Mysql->describeTable('albums', NULL) #4 C:\wamp\www\zf_tutorial\library\Zend\Db\Table\Abstract.php(534): Zend_Db_Table_Abstract->_setupMetadata() #5 C:\wamp\www\zf_tutorial\library\Zend\Db\Table\Abstract.php(269): Zend_Db_Table_Abstract->_setup() #6 C:\wamp\www\zf_tutorial\application\controllers\IndexController.php(8): Z in C:\wamp\www\zf_tutorial\library\Zend\Db\Adapter\Pdo\Abstract.php on line 131

  98. 98 Rob...

    koushika,

    The error message tells you what is wrong:

    "Access denied for user 'koushika'@'localhost'"

    Regards,

    Rob…

  99. 99 Nicky

    Great tutorial

  100. 100 Calista

    Dear Rob,

    since there is no german translation I've done it know at my own risk. Is it okay if I put it on my website with reference to you?

    Could be done till this weekend :-)

    bye, calista

  101. 101 Rob...

    Calista,

    Of course!

    Regards,

    Rob…

  102. 102 priya

    1. Please let me know , why you use views files as .phtml instead of .php

    2. i could see that the models also include eg: albumform you set the label, test field in the model file when you could put all these things in view file .

  103. 103 ShaileshPatel

    Hi,
    Can any body help??
    I'm new in ZF. And I need to implement an ajax base search feature in it using ZF. But It gives me error about missing path and/or forbidden error. I thnk that my problem is in either bootstrap or in controller.

  104. 104 Nour

    Halo Rob,
    I have a question.How can i call an action of a controller in other controller.
    I tried to instantiate but i get 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
    thanks

  105. 105 Rob...

    Nour, you shouldn't need to do this, but, if you must, instantiate the controller with the correct arguments and it'll probably let you call it correctly.

    Regards,

    Rob…

  106. 106 Nour

    How can i do that
    Regards,
    Nour

  107. 107 Jeff Dickey

    There's probably a common mistake for people who went through this tutorial and got an 'Internal Server Error' on the first test.

    Make sure that you put the .htaccess as specified in the zf-tutorial-dev/public directory, *NOT IN THE BASE* zf-tutorial-dev/ directory. The Apache error.log messages are less than obvious on this.

  108. 108 nightguy

    Thank You!

    Great tutorial.

  109. 109 Valdeva Crema

    Rob - Thank you so much for this tutorial. It gave me exactly what I needed to get started.

  110. 110 nglan

    Hi Rob. Thanks for tutorial. I did step by step and after I did "setting up the view" then "Testing each ontroller/action by navigating the urls shown earlier should display the four titles within the web browser" result is just url http://localhost/zf-tutorial/public/ work. It display title "My Album" but 3 URLs: http://localhost/zf-tutorial/public/index/add http://localhost/zf-tutorial/public/index/edit and http://localhost/zf-tutorial/public/index/delete, browser said error 404 not found on server. May you help me Rob? Thanks

  111. 111 Rob...

    nglan,

    You haven't set up mod_rewrite on your server. Read the bit in red at the top of this page

    Regards,

    Rob…

  112. 112 nglan

    Thank you so much Rob.

  113. 113 nglan

    Hello Rob.

    In httpd.conf file. I've change this line:
    #LoadModule rewrite_module modules/mod_rewrite.so
    to:
    LoadModule rewrite_module modules/mod_rewrite.so
    And change all lines:
    AllowOverride None
    to
    AllowOverride All

    Then restart Apache. But when browser URL http://localhost/zf-tutorial/public/. It display:
    Internal Server Error
    The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator, [no address given] 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.

    The last line in my error.log file is:
    [Thu Jul 17 11:12:32 2008] [alert] [client 127.0.0.1]C:/Apache22/htdocs/zf-tutorial/public/.htaccess: Invalid command 'php_flag', perhaps misspelled or defined by a module not included in the server configuration

    My .htaccess file content:

    # Rewrite rules for Zend Framework
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule .* index.php
    # Security: Don't allow browsing of directories
    Options -Indexes
    # PHP settings
    php_flag magic_quotes_gpc off
    php_flag register_globals off
    php_flag short_open_tag on

    If I delete 3 last lines. All URLs (http://localhost/zf-tutorial/public/, http://localhost/zf-tutorial/public/index/add, http://localhost/zf-tutorial/public/index/edit, http://localhost/zf-tutorial/public/index/delete) work OK.

    I don't know why? I do something wrong? May you tel me the reason? Thank you Rob.

  114. 114 Hon

    I have set baseUrl to '/workspace_zend/zf-tutorial/public/'
    but if I open link 'http://127.0.0.1/workspace_zend/zf-tutorial/public/'
    so nothing show me.
    When I display html code of the page, browser show this:

    No error show

    Thank you

  115. 115 Hon

    I have set baseUrl to '/workspace_zend/zf-tutorial/public/'
    but if I open link 'http://127.0.0.1/workspace_zend/zf-tutorial/public/'
    so nothing show me.
    When I display html code of the page, browser show only basic html code but without inserted values of variables. For example is ignored $this->escape($this->title); in the layout.phtml file

    No error show

    Thank you

  116. 116 Hon

    You can ignore my last comments, I found that stupid mistake :)

  117. 117 Nguyễn 85

    Please tell me the file contain database config. I want to change database username 'rob'@'localhost' to 'root'@'localhost' .

    Thanks !

  118. 118 Ramiro

    Hola rob… , I'm a new to Zend and PHP too, nice tutorial, but I am getting same error as : Kyia, mdrisser, Trinath and nglan , can you help me about it this error , because I try so hard , but I can not , I tried this Options Indexes FollowSymLinks MultiViews AllowOverride Allin my config /etc/apache2/apache2.conf because my httpd.conf is empty. also I have Loaded Modules mod_rewrite, Saludos

  119. 119 Rob...

    Hi,

    I'm very sorry, but Apache is set up correctly on my servers and I don't have the ability to fix other systems.

    Regards,

    Rob..

  120. 120 Ramiro

    Hello , I fix it with this
    change .htaccess :
    RewriteEngine on
    RewriteCond %{SCRIPT_FILENAME} !-f
    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1

    Thanks for great tutorial

  121. 121 Attila

    Hello!

    Just discovered the '404 solution':
    The problem gone when wwwroot is set to '/var/www/zf_project/public' directly, not just to '/var/www'.
    Hope it helps.

  122. 122 nader

    hi
    i tried the tutorial and it's work
    the tutorial is very good and perfect
    but i see that the zend or your tutorial need high time for execution
    so he need 2 secondes for only 3 lines in database
    so imagine with 1555555 lines
    i heard about zend optimiser
    u think bob is good for your application?
    or u have other idea to optimize your code
    have nice day

  123. 123 Wa'el

    Thank you so much!!!! Flawless tutorial… really awesome

    just 2 quick questions:
    1- The pages takes considerable time to execute, how can i reduce that?
    2- I am going to build a new website and i was wondering if Zend is the best framework for me. CakePHP, Zend, Symfony, and CodeIgniter seem to be good candidates, which one is the most powerful? and why?

  124. 124 mik

    I managed to get the Albums tutorial to work. I am trying to adapt this tutorial into my project.
    I have an IndexController.php file that contains the indexAction, the loginAction and the registerAction. I have managed to set up the phtml files and the viewers are working fine displaying simple messages like 'this is the login action', 'this is the register action' etc.
    My problem is how to incorporate the UserController into the above scenario, to authenticate, update the db etc.
    Also, how do i get to display 'users' from UserController using 'localhost'. At the moment it seems i can only display actions in the IndexController.

  125. 125 nader

    hello
    i found problem for to add
    “find” type methods in class Albums in Albums.php
    for exemple if i hda to count number of pop artist, rock artis… and display them in samed page
    i tried manually and it's work ok (for example)
    $select = albums->select()

    ->where('ARtis= ?', 'POP');
    but i don't see how create function like this
    function count($Artist)
    AND so i called this function in index.phtml with their parameter a pop or rock
    thank for helping

  126. 126 mik

    can someone tell me how to view UserController actions in 'localhost'. How do i relate the IndexController with the UserController. I am cofused as to how other controllers apart from the IndexController are used with Zendframe.

  127. 127 nader

    how i add paginate zend in index.php??

  128. 128 itay

    I managed to load /zf-tutorial/public page. When I am trying to access add/edit/delete I get error 404.

    The AllowOverride is All.
    I tried changing .htaccess

    Thanks.

  129. 129 DatLQ

    I have problem
    I can't insert fields Date into DB Oracle from application Zend FrameWork
    Please help me!
    mail :datlq@luvina.net

  130. 130 itay

    I wanted to add to reply #128 (above)
    that if I update forward indexAction to add Action it's works.

    function indexAction(){

    $this->_forward('add');

    }

    Please advice.

  131. 131 magnums

    Hi,
    the scripts as below will show all record. It's work fine.
    ———————–
    $albums = new Albums();
    $this->view->albums = $albums->fetchAll();
    ———————–
    But i want to show some or one record by replace with:

    $albums = new Albums();
    $this->view->albums =
    $albums->fetchRow("select * from albums where id=2″);

    It does not work.
    How to do that?

    Thank in advance.
    magnums

  132. 132 Rob...

    magnums,

    Try:

    $this->view->album $albums->fetchRow('id=2′); 
    

    or

    $this->view->album2 $albums->fetchAll('id < 10′); 
    

    Regards,

    Rob…

  133. 133 nader

    hi rob
    how can i put many sql requete in same page like index
    for example get artist by kinf of music in different table

  134. 134 Francisco

    Hi Rob,
    Great tutorial. Now at last I understand the MVC pattern as well as many others used in the ZF. I have bought 'Zend Framework in Action' which is also great, but I find this tutorial is clearer than the first 3 chapters of the book.

    Still, I have a problem with the link to the css file. If I use '<link rel="stylesheet" type="text/css" media="screen"
    href="baseUrl();?>/css/site.css" />' in layout.phtml it doesn't get connected to site.css (If you look at the source code in the browser it points to 'zf-tutorial/public/index.php/css/site.css'
    which obviously doesn't exist as index.php is not a directory.
    However if I erase 'baseUrl();?>' and just leave '/css/site.css' it works fine.
    I have the same problem with the images and css files in chapter 3 of your book but I haven't tried the above solution.
    I guess there is something wrong with my local configuration but I can't find what. I have carefully followed the tutorial step by step.

    Thank you for sharing your knowledge with us, newbies.

    Francisco
    Spain

  135. 135 Francisco

    Hi again Rob,
    there is a typo in my previous comment .The original link to the css file should read
    '<link rel="stylesheet" type="text/css" media="screen"
    href="baseUrl();?>/css/site.css" />'

    and not:
    '…href="baseUrl();?>"'

    as I wrote.

    Thanks again

    Francisco
    Spain

  136. 136 Chris

    Hi.

    There is one thing i'd like to ask.
    Is there a Linux version of Zend Framework and if there is, where can I download it?

    Thank you.

    Chris

  137. 137 Francisco

    Hi,
    I'm afraid I've been a bit dim about the path to the css file, mentioned in comments 134 and 135. I've forgotten that when on a remote server 'baseUrl'+/css/site.css will point to the site 'public' directory. So for the tutorial it will point to,let's say, 'www.zf-tutorial.com/css/site.css' which will effectively read the style rules.
    Sorry for being so dumb!

    Thank you

    Francisco

  138. 138 Rob...

    ah!

    Glad you sorted it, Francisco.

    Regards,

    Rob…

  139. 139 Arash Keshmirian

    Hi Rob,

    I've found an error in the tutorial text:

    (Page 10)
    "View helpers live in the application/views/helpers subdirectory and are named
    {Helper name}.php (the first letter must be uppercase) and the class inside must be called
    Zend_Controller_Helper_{Helper name} (again, uppercase first letter)."

    I believe it should be "must be called Zend_View_Helper_{Helper name}".

    Great tutorial though; it really helped me along. I'm looking forward to the book!

    Cheers,
    Arash

  140. 140 stav

    Excellent work. I'm a nooby and this tutorial worked great; very clear and easy to read. Good job, keep up the good work. thanks.

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

Leave a Reply

Pre order