Getting Started with Zend Framework 1.5, 1.6 and 1.7

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.

This tutorial has been tested on versions 1.5.x, 1.6.x and 1.7.x of the Zend Framework. It will not work on any version prior to version 1.5.0.

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

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

Translations

French by Guillaume Rossolini: Débuter avec Zend Framework 1.5
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
Russian by Sergey Mitroshin Начало работы с Zend Framework

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

275 thoughts on “Getting Started with Zend Framework 1.5, 1.6 and 1.7

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

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

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

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

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

  7. 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:wwwrasprodagafrontlibraryZendDbAdapterPdoAbstract.php:104 Stack trace: #0 C:wwwrasprodagafrontlibraryZendDbAdapterAbstract.php(390): Zend_Db_Adapter_Pdo_Abstract->_connect() #1 C:wwwrasprodagafrontlibraryZendDbAdapterPdoAbstract.php(206): Zend_Db_Adapter_Abstract->query(‘DESCRIBE `album…’, Array) #2 C:wwwrasprodagafrontlibraryZendDbAdapterPdoMysql.php(137): Zend_Db_Adapter_Pdo_Abstract->query(‘DESCRIBE `album…’) #3 C:wwwrasprodagafrontlibraryZendDbTableAbstract.php(605): Zend_Db_Adapter_Pdo_Mysql->describeTable(‘albums’, NULL) #4 C:wwwrasprodagafrontlibraryZendDbTableAbstract.php(534): Zend_Db_Table_Abstract->_setupMetadata() #5 C:wwwrasprodagafrontlibraryZendDbTableAbstract.php(269): Zend_Db_Table_Abstract->_setup() #6 C:wwwrasprodagafrontapplicationcontrollersIndexController.php(8): Zend_Db_Table_Abstract->__construct() #7 C:wwwrasproda in C:wwwrasprodagafrontlibraryZendDbAdapterPdoAbstract.php on line 104

  8. Mister Olympia,

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

    Regards,

    Rob…

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

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

  11. 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…

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

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

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

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

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

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

  18. 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…

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

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

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

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

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

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

  25. 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 ?

  26. 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!

  27. 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!

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

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

  30. 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?

  31. 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:wwwzfwlibraryZendDbAdapterMysqli.php:280

    So I try changing the adapter to MYSQL:
    Fatal error: Uncaught exception ‘Zend_Exception’ with message ‘File “ZendDbAdapterMysql.php” was loaded but class “Zend_Db_Adapter_Mysql” was not found in the file’ in W:wwwzfwlibraryZendLoader.php:88

    Took a look in ZendDbAdapter 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.

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

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

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

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

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

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

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

  39. 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();
    }
    }
    ?>

  40. 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);
    }

  41. 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);
    }

  42. 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?

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

  44. @Trinath, did you check your apache config?

    Search for something like this:

    Options FollowSymLinks
    AllowOverride None

    Make it:
    AllowOverride All

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

  46. 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?

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

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

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

  50. Typo, top of page 10:

    “…we require form
    the request object.”

    should be ‘from’.

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

  52. 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?

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

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

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

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

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

  58. 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!

  59. 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:wampwwwzf_tutoriallibraryZendDbAdapterPdoAbstract.php:131 Stack trace: #0 C:wampwwwzf_tutoriallibraryZendDbAdapterAbstract.php(390): Zend_Db_Adapter_Pdo_Abstract->_connect() #1 C:wampwwwzf_tutoriallibraryZendDbAdapterPdoAbstract.php(206): Zend_Db_Adapter_Abstract->query(‘DESCRIBE `album…’, Array) #2 C:wampwwwzf_tutoriallibraryZendDbAdapterPdoMysql.php(137): Zend_Db_Adapter_Pdo_Abstract->query(‘DESCRIBE `album…’) #3 C:wampwwwzf_tutoriallibraryZendDbTableAbstract.php(605): Zend_Db_Adapter_Pdo_Mysql->describeTable(‘albums’, NULL) #4 C:wampwwwzf_tutoriallibraryZendDbTableAbstract.php(534): Zend_Db_Table_Abstract->_setupMetadata() #5 C:wampwwwzf_tutoriallibraryZendDbTableAbstract.php(269): Zend_Db_Table_Abstract->_setup() #6 C:wampwwwzf_tutorialapplicationcontrollersIndexController.php(8): Z in C:wampwwwzf_tutoriallibraryZendDbAdapterPdoAbstract.php on line 131

  60. koushika,

    The error message tells you what is wrong:

    “Access denied for user ‘koushika’@’localhost’”

    Regards,

    Rob…

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

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

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

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

  65. 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…

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

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

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

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

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

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

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

    Thanks !

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

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

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

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

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

  78. 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?

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

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

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

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

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

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

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

  86. magnums,

    Try:

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

    or

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

    Regards,

    Rob...

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

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

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

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

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

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

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

  94. why i got this message in the browser:http://localhost/zftu/public
    http 400 err request?

    i open apache’s error.log file and found this:
    [error] [client 127.0.0.1] Invalid URI in request GET /zftu/public/ HTTP/1.1

    PS: my apache httpd.conf as follows:
    Alias /zftu “F:/CVS/zftu”

    AllowOverride ALL
    Options FollowSymLinks

    Order allow,deny
    Allow from all

    Order deny,allow
    Deny from all

    my apache version is apache2.2, php is php5.2.6,mysql5.22community
    pls can help me?

  95. I’m having some problems after going through this tutorial that someone here might be able to help me with.

    The first problem is I get this error: Zend_Db_Table_Exception: No adapter found for Albums in C:webserverhtdocszf-tutoriallibraryZendDbTableAbstract.php on line 548 when I go to http://zf-tutorial.localhost/.

    The second problem is I get this error: Zend_Controller_Dispatcher_Exception: Invalid controller specified (zf-tutorial) in C:webserverhtdocszf-tutoriallibraryZendControllerDispatcherStandard.php on line 249 when I go to http://localhost/zf-tutorial/index/add. I’m having a hard time finding any information online for these errors. Thanks for your help in advance.

  96. Disregard my question, I figured it out myself. It helps to create an instance of the database. :-) Somehow I skipped right over it in the tutorial.

  97. @dwlitt
    i think your configuartion isnt good.
    You typed into your url …/public/
    So, if configuration is good, and you are recieveing 404 you probably
    1. dont have publicController
    2. have apache down
    have you tried to add this line ? $controller->throwExceptions(true); // should be turned on in development time
    maybe you have wrong directory setup as well.
    Your httpd.conf should point to the folder where your public content is (e.g. public, www, html…)

  98. Hi Rob,

    This tutorial is really good. However how can I trap the possibility that a user will enter an invalid URL (by directly typing it on the browsers address bar.

    Example:
    http://localhost/zf-tutorial/public/anything_here

    The above example will throw an error message Fatal error: Uncaught exception ‘Zend_Controller_Dispatcher_Exception’ with message ‘Invalid controller specified (anything_here)’ in C:wampwwwzf-tutori…’

    because the word anything_here has been added manually to the address bar.

    How can I display a custom 404 error message.

    Thanks

    Sanny

  99. Hi Rob,
    I was able to figure it out.

    I just comment out the line
    $frontController->throwExceptions(true);

    and added an ErrorController and neccessary files.

    Thanks

    Sanny

  100. The Albums model doesn’t seem to load, or include itself;

    [code]
    // In IndexController, indexAction();

    $albums = new Albums();
    $this->view->albums = $albums->fetchAll();
    [/code]

    And I get this error;

    [code]
    Zend_Loader::include_once(Albums.php) [zend-loader.include-once]: failed to open stream:
    [/code]

    It never seems to load the Model file. Earlier in this thread you mention its because you have to include the path inside the php include, but I can find no documentation that gives clarification on the issue.

    Could you clarify what you meant, and how to resolve the inclusion of the albums model?

  101. I solved the problem of the Albums model not seem to load, or include itself;

    Here’s how I solved it.

    [code]
    // I put the following inside my index.php file in the public folder, otherwise known as the the bootstrap file;
    // Add the models directory to the inclusion path.
    ini_set('include_path', ini_get('include_path'). '.;' . '../application/models/');
    [/code]

    Here’s my question — why do I have to even tell Zend to load the models directory, why doesn’t it do it itself?

    In CodeIgnitor you don’t need to say “include: ‘models’”.

    Perhaps I’ve missed something. Is there a way of making Zend automatically pick up the models directory without me coding it in?

    Anyway, the above solved the problem, but an automatic solution would be great.

    Thanks

  102. Hi Rob,
    I bought your Ebook “Zend Framewaork in Action”. It’s did not said how to using system command with Zend Framewaork like Zend_Getopt or Zend_Console. I read docs from Zend website but not understand and not answer my question. Rob, Did you have a sample of using Zend call linux command ? how to do that? , please give me a sample.

    Thank in advance.
    Satit P.

  103. AD,

    Zend Framework doesn’t make any assumptions about where your models are. As you noticed, If you add your models directory to the path, then Zend_Loader’s autoload system will load them for you.

    Regards,

    Rob…

  104. Warning: include() [function.include]: Failed opening ‘../application/models/Albums.php’ for inclusion (include_path=’../application/default/controllers;.;../library;./application/default/models/;.;C:php5pear’) in C:wampwwwZendtestapplicationdefaultcontrollersIndexController.php on line 3

    hi… nice tutorial but i am stcuk on this error… wat is basically happening, imho, is that it is not finding my models folder and thus cannot see my album class…

    i have tried manually including the classes, using require_once, I get a new problem.

    require_once(../application/models/Albums.php) [function.require-once]: failed to open stream: No such file or directory in C:wampwwwZendtestapplicationdefaultcontrollersIndexController.php on line 3

    In sum, i believe Zend still cannot find my directory…

    please help me

  105. Hi Kevina,

    As you probably worked out, using relative paths with require() is a bit tricky as you don’t know what the current working directory is.

    dirname(__FILE__) will give the directory of the current file which is quite useful for cases like this. Alternatively, use a define like APP_ROOT that’s set in the bootstrap or add the models directory to the include path.

    Regards,

    Rob…

  106. Well. Somethings working if I go to my main site I get “My Albums”

    but if I go to /index/add I get a 404 not found.

    ps. I am at page 7

  107. Hello Rob,

    Thanks for a concise and well-structured tutorial for beginners like us. working successfully for me..am on my way to create a project on ZF..thanks again…

  108. Thanks for the benevolent help!

    I’ve looked at the framework.zend.com tutorial and yours and I’m curious why Zend doesn’t add models to their path as well. They have protected methods to call the model scripts using require_once explicitly. They also put forms in their own directory, which would require adding forms to the default path. I am assuming that we can use your method as long as we are careful to prepend meaningful names to our model / form classes and files as to not clobber other filenames in the global include path?

    Just curious what your thoughts are on this?

  109. In the indexController::indexAction method, I get the error:

    Warning: Zend_Loader::include_once(Albums.php) [function.Zend-Loader-include-once]: failed to open stream: No such file or directory in…

    at the line:
    $albums = new Albums();

    I can do:
    require_once APPLICATION_PATH . ‘/models/Albums.php’;

    to correct this. However shouldn’t the loader find the appropriate models class? I don’t think I should have to “require_once” the class file everytime I want to instantiate a model class.

    Did I miss something earlier on in the tutorial?

  110. Nevermind my previous post. I was merely missing “…/application/models” from my include path.

  111. exception ‘Zend_Db_Table_Exception’ with message ‘No adapter found for Albums’

    怎样解决这个问题??

  112. Hi,

    Can anyone tell me how to or give me a site where it explains how i can pass a value that it isnt in the form ? For example i log in to add an album .. it automatically sends to the DB my username with the registry ?

    Regards

  113. Great tutorial so far, but just ran into a problem when connecting to my db. Am getting — Access denied for user: ‘cloozle@localhost’ (Using password: YES)’

    I know this is a valid user accnt with full privileges as I am using it for other scripts.

    I am on a shared server and connecting to localhost, with mysqli.default_socket = /tmp/mysql5.sock set in my .ini file.

    Any thoughts from anyone?

    Thanks!

    Marc

  114. Re: #179 I found the solution.

    I needed to add:
    db.params.unix_socket=”/tmp/mysql5.sock”

    to the .ini file

    Hope this helps someone else who runs across this issue.

  115. helpp i got this error on this line
    $form->submit->setLabel(‘Add’); saying Fatal error: Call to a member function setLabel() on a non-object, what did i do wrong?

  116. hahah nevermind,forgot to add $this->addElements(array($id, $title, $content, $submit)). thanks for this great tutorial rob :D

  117. help i have same problem as kocu
    $form->submit->setLabel(‘Add’);
    Fatal error: Call to a member function setLabel() on a non-object

    need help. Thanks

  118. Hey Rob

    Just run your script and got this “Fatal error: Using $this when not in object context in C:xampphtdocszf_tutorial-150-with-zfapplicationviewsscriptsindexindex.phtml on line 1″

    Can you help me to move beyond this please?

    Info:
    PHP 5.2.6
    Apache 2.2
    MySql 5.0.67

  119. I have been able to set the MVC, i am able to display the index page but when i click on the link to CRUD,i only see their heading without any forms being display,Folks kindly help me out.

  120. in the begining of your tutorial, is written:

    “Your zf-tutorial/library should now contain a sub-directory called Zend and a file called Zend.php.”

    maybe i missing it? but, what is code for zend.php file? (not found either in zf downloaded file)

    coz i found this on my localhost. “Fatal error: Class ‘Zend’ not found in C:xampphtdocszf-tutorialindex.php on line 7″

    thanks.

  121. Gosh…that’s why i feel so much weird last night. okey…i just found the right folder. i will step up to your last tutorial. perhaps, i’ll came back here later :). thanks rob

  122. Hola, Rob!

    Well, I just started going through your tutorial and will order zend framework in action!

    I would like, to make your tutorial perfect, to my eyes, to ask you:

    Please, just add a login/logout section to it.

  123. Rob, is it okay for me to translate your tutorial into dutch and post it somewhere? (I’m thinking of starting an own blog). I will ofcourse provide you with the link…

  124. Thank you! May I ask you what software you use to get the the code examples in the pdf coloured? Or do you just colour it manually?

  125. Hi Rob,

    Great article. You recommend that using one model for each table is the way to go, however i’d be interested in seeing how relationships would work.

    I’ve seen in the manual about refrence maps and using functions such as findParentRow() but this seems a bit resource intensive to me when the join could just be written into a model. In addition, I am yet to get this to work !!!

    I suppose you could add a join using $select->join in your model but this seems a bit messy to me after you mentioned having one model to one database table?

    Some clarification on what is the “recommended” way of going about relationships would be good.

    Thanks!

    Jonathan.

  126. Hi Rob,

    Thanks for your great article. But i have got a question about ZF.

    In older days (when we not use Frameworks :) when i want to show a login form or a “logout” link on all my pages with sidebar, what i have to do is just include the “loginout.php” in “sidebar.php” and my “loginout.php” is like this:

    check()) {
    echo “Logout
    } else {
    showLoginForm();
    }

    ?>

    But how can do this with ZF? how can i include other controllers/action on my page?

    second question:

    With ZF, when i call the “/user/login” from browser, it renders the whole page with header, footer, sidebar etc. this is normal :) but (back to Question 1) i want (when i not request it from URL, when i include) it must just render the needed part (example: just the login form)

    how can i do this?

    thanks.

  127. Hi Rob,

    Thanks for a great tutorial – Really Really clear – I had a lot of problems with the quick start tutorial on the Zend site, but this worked better for me because it’s based on mysql…

    One thing i haven’t figured out, is that my zend libraries are not in the same place as yours ( I had installed them previously) and since I have not changed the include path, I would kind of expect it not to work, but it does… Not complaining, but sure that’s going to bite me later, so if anyone has any ideas…

    Thanks again for the help
    R

  128. Dear Rob
    I would like to know how to do salting on the password during registration so it can be registered in the database hashed
    I really really need help
    Best regards,
    JOJO

  129. AnotherRob,

    Your include_path in your php.ini probably sets up your install or Zend Framework.

    jojo,

    Look up SetCredentialTreatment() in Zend_Auth.

    Regards,

    Rob…

  130. Dear Rob,
    Really gr8 article. I am new to Zend. and this is gr8 article for gr8 start to zend. Thank You very much.
    I tried the tutorial.I got an error..
    Fatal error: Call to a member function toArray() on a non-object in C:xampphtdocstechnozendindex.php on line 22

    The line is:
    $db = Zend_Db::factory($config->db->adapter,$config->db->config->toArray());

    I tried ‘params’ instead ‘config’. now its
    working properly
    $db = Zend_Db::factory($config->db->adapter,$config->db->params->toArray());
    Now it working properly

  131. Thank you for a good tutorial. Hope to see more.

    I kept getting the 404 error when I was trying to load http://localhost in the example that plays with Albums.php. I tracked the problem down to the line (inside IndexController.php) that says $this->view->albums = $albums->fetchAll();
    So, I knew it was more likely a database connection problem.

    As it turns out, php.ini was not configured to correctly connect with the database.
    I needed to uncomment:
    extension=php_pdo.dll
    extension=php_pdo_mysql.dll

    And, I also added:
    extension=pdo.so
    extension=pdo_mysql.so

    Save php.ini and restart apache, and the problem was fixed.

    I’m posting this in case someone runs into the same problem in the future

  132. I found some error at page 10 under styling:
    “that collects the information we require *form* the request object” form should be from.
    and
    “and the class inside must be called Zend_Controller_Helper_{Helper name}”
    it should be Zend_View_Helper_{Helper name}

  133. Hi,
    Warning: include(Zend.php) [function.include]: failed to open stream: No such file or directory in C:xampphtdocszf-tutorialindex.php on line 5

    Warning: include() [function.include]: Failed opening ‘Zend.php’ for inclusion (include_path=’.;./library/;./application/models.;C:xamppphppear’) in C:xampphtdocszf-tutorialindex.php on line 5

    Fatal error: Class ‘Zend’ not found in C:xampphtdocszf-tutorialindex.php on line 6
    What should I do?
    I use (ZF 0.2)

  134. Hi,
    Whta should I do (ZF 0.2)?
    Warning: include(Zend.php) [function.include]: failed to open stream: No such file or directory in C:xampphtdocszf-tutorialindex.php on line 5

    Warning: include() [function.include]: Failed opening ‘Zend.php’ for inclusion (include_path=’.;./library/;./application/models.;C:xamppphppear’) in C:xampphtdocszf-tutorialindex.php on line 5

    Fatal error: Class ‘Zend’ not found in C:xampphtdocszf-tutorialindex.php on line 6

  135. hi,
    so I use ZF 1.7, and
    Warning: include(Zend/Loader.php) [function.include]: failed to open stream: No such file or directory in C:xampphtdocszf-tutorialpublicindex.php on line 9

    Warning: include() [function.include]: Failed opening ‘Zend/Loader.php’ for inclusion (include_path=’.;../library/;../application/models;.;C:xamppphppear’) in C:xampphtdocszf-tutorialpublicindex.php on line 9

    Fatal error: Class ‘Zend_Loader’ not found in C:xampphtdocszf-tutorialpublicindex.php on line 10
    what’s wrong?

  136. Hi Rob,

    I try to make your tutorial code running on my Apache 2 server (I use XAMPP to have all the newest components of WAMP instalation), but I have a problem: if runing the code of tutorial as is, it breaks down my Apache. I noticed something is wrong with lines
    “// directory setup and class loading
    set_include_path(‘.’ . PATH_SEPARATOR . ‘../library/’
    . PATH_SEPARATOR . ‘../application/models’
    . PATH_SEPARATOR . get_include_path());”

    I found in another tutorial something like
    “define(‘ROOT_DIR’, dirname(dirname(__FILE__)));
    set_include_path(‘.’
    . PATH_SEPARATOR . ROOT_DIR.’/library/’
    . PATH_SEPARATOR . ROOT_DIR.’/application/’ // kodel tik /app o ne /app/models’
    . PATH_SEPARATOR . ROOT_DIR.’/library/incubator’ // ka duoda sita eilute???
    . PATH_SEPARATOR . get_include_path()
    );”

    When I use the code above, I get the error “Class ‘Albums’ not found in C:xampphtdocszf_tutorial-150applicationcontrollersIndexController.php on line 8″, what in your tutorial is “$albums = new Albums();”.

    What am I doing wrong? How to fix this error?
    Thank you in advance!

  137. K,

    Try:

    define('ROOT_DIR', dirname(dirname(__FILE__)));
    set_include_path('.' . PATH_SEPARATOR . ROOT_DIR . '/library/'
    . PATH_SEPARATOR . ROOT_DIR . '/application/models'
    . PATH_SEPARATOR . get_include_path());"

    Regards,

    Rob…

  138. Hi Rob,

    As you suggested, I tried to add “models”, but after that I got my Apache server not responding for short time and then it went down totally (totally the same as I use your original files). I expect something is wrong with my XAMPP instalation (as I wrote in my previous post, the instalation is typical, but all necessary tools, options and functions are installed. At least I believe they do). Maybe others had met this problem as well and can share their experience? Rob, what would be your suggestion in this case?

  139. Hi Rob, thanks for the great tutorial.
    Out of all the one that I found it was the easiest to understand,
    especially your screenshot of the folder structure.

    I have found one problem (I think). In the PDF (http://akrabat.com/wp-content/uploads/getting-started-with-zend-framework-152.pdf)
    you show the entry for setting up a virtual server for this tutorial.

    ServerName zf-tutorial.localhost
    DocumentRoot /var/www/html/zf-tutorial/public

    AllowOverride All

    Stating that the server would then have access to the public/ directory. This is correct.
    You then say to put the bootstrap (index.php) under the public directory.

    I was having some problems so I downloaded your example code
    to compare with what I had done. I noticed that in your example code you had placed the index.php file under the parent directory
    of public. This means the virtual host entry is wrong as it should point to zf-tutorial not public.

    Am I correct in this?

    Regards
    Steven Wright

  140. I need help. i got a message “Fatal error: Call to a member function setLabel() on a non-object in G:ServerSitesZendapplicationcontrollersIndexController.php on line 50″
    on line “$form->submit->setLabel(‘Save’);”.
    The similar message from Lukas is left without answer.
    Can smb explain me what am i gonna do?
    Thanx!

  141. Then i had a problem with CONNECTION TO PDO_MYSQL I went to php.ini and set

    ;extension=php_bz2.dll
    extension=php_curl.dll
    ;extension=php_dba.dll
    ;extension=php_dbase.dll
    extension=php_exif.dll
    ;extension=php_fdf.dll
    extension=php_gd2.dll
    ;extension=php_gettext.dll
    ;extension=php_gmp.dll
    ;extension=php_ifx.dll
    ;extension=php_imap.dll
    ;extension=php_interbase.dll
    ;extension=php_ldap.dll
    extension=php_mbstring.dll
    ;extension=php_mcrypt.dll
    ;extension=php_mhash.dll
    ;extension=php_mime_magic.dll
    ;extension=php_ming.dll
    ;extension=php_msql.dll
    ;extension=php_mssql.dll
    extension=php_mysql.dll
    extension=php_mysqli.dll
    ;extension=php_oci8.dll
    ;extension=php_openssl.dll
    extension=php_pdo.dll
    ;extension=php_pdo_firebird.dll
    ;extension=php_pdo_mssql.dll
    extension=php_pdo_mysql.dll
    ;extension=php_pdo_oci.dll
    ;extension=php_pdo_oci8.dll
    ;extension=php_pdo_odbc.dll
    ;extension=php_pdo_pgsql.dll
    extension=php_pdo_sqlite.dll
    ;extension=php_pgsql.dll
    ;extension=php_pspell.dll
    ;extension=php_shmop.dll
    ;extension=php_snmp.dll
    ;extension=php_soap.dll
    extension=php_sockets.dll
    extension=php_sqlite.dll
    ;extension=php_sybase_ct.dll
    ;extension=php_tidy.dll
    ;extension=php_xmlrpc.dll
    ;extension=php_xsl.dll
    ;extension=php_zip.dll

    Restart Server –> Ok

    when I had some problems that ALBUMS CLASS NOT FOUND I went to the tutorials start and found in index.php (/public/) rows

    // directory setup and class loading
    set_include_path(‘.’ . PATH_SEPARATOR . ‘../library/’ . PATH_SEPARATOR . ‘../application/models’ . PATH_SEPARATOR . get_include_path());

  142. ok i dont know how to say thank you for your realy great tuto. so i simply say good job and well done.

    good luck man

  143. Hi,

    I get following error :

    Fatal error: Class ‘Albums’ not found in……………..

    Any ideas as to why?

    Thanks in advance

    Dan

  144. define(‘APPLICATION_PATH’, realpath(dirname(__FILE__) . ‘/../application/’));
    set_include_path(
    APPLICATION_PATH . ‘/../library’
    . PATH_SEPARATOR . get_include_path()
    );

    so what would I change this to? I have another controller that uses the same models folder and it works fine….?

  145. SOLVED IT!

    The following needed to be done:

    define(‘APPLICATION_PATH’, realpath(dirname(__FILE__) . ‘/../application/’));
    set_include_path(
    APPLICATION_PATH . ‘/../library’
    . PATH_SEPARATOR . get_include_path()
    . PATH_SEPARATOR . realpath(dirname(__FILE__) . ‘/../application/models’));

  146. How would I go about adding a search page to this?

    Using a brand new controller?

    Thanks for your help if I havent said so already

  147. controller wide. Simply want users to be able to search (album title in this context) and for those relating albums to be displayed….?

    Dan

  148. Im probably beginning to be a bit of a pain now! I am trying to create my own rss feed from the outputted data of this tutorial.

    I have tried the following controller action:

    public function feedAction()
    {
    // Change layout to blank.phtml (empty file)
    $this->_helper->layout->setLayout(‘blank’);

    // Set feed values
    $array['title'] = ‘Forum feed’;
    $array['link'] = ‘http://www.somewhere.com/’;
    $array['description'] = ‘This is guestbook feed’;
    $array['charset'] = ‘utf8′;
    // You need to change this line to read $array['charset'] = ‘utf-8′; (Note the change to the ‘utf8′ part)

    // Loop through db records and add feed items to array
    $model = $this->_getModel();
    foreach($model->fetchEntries() as $one_item)
    {
    $array['entries'][] = array(
    ‘title’ => $one_item['email'],
    ‘link’ => ‘http://www.somewhere.com/123′,
    ‘description’ => $one_item['comment']
    );
    }

    // Import rss feed from array
    $feed = Zend_Feed::importArray($array, ‘rss’);

    // Send http headers and dump the feed
    $feed->send();
    }

    Im getting the following error though:

    Method “_getModel” does not exist and was not trapped in __call()

    Any Help why?

    Thanks again

  149. Hi, i am having trouble with edit Album with Zend_Form, the moment the script enters the isValid method to check before updating, the webpage goes blank. If i take out the part of the script that populates the form based on the get id variable which in effect become add Album page, the isValid methos runs fine as expected but only when i use to edit the existing id, just blank, no error nothing!

    I am following the exact structure as in this example. Primarily i am following your book, but because you haven’t included a working example like this…..

  150. No I havent set it as its own function at all. How and why do I go about doing this?

    Dan

  151. OK heres my controller.

    _getModel();
    foreach($model->fetchEntries() as $one_item)
    {
    $array['entries'][] = array(
    ‘title’ => $one_item['email'],
    ‘link’ => ‘http://www.somewhere.com/123′,
    ‘description’ => $one_item['comment']
    );
    }

    // Import rss feed from array
    $feed = Zend_Feed::importArray($array, ‘rss’);

    // Send http headers and dump the feed
    $feed->send();
    }

    protected function _getModel()
    {
    if (null === $this->_model) {
    // autoload only handles “library” compoennts. Since this is an
    // application model, we need to require it from its application
    // path location.
    require_once APPLICATION_PATH . ‘/models/ForumForm.php’;

    $this->_model = new Model_ForumForm();
    }
    return $this->_model;
    }

    public function indexAction()
    {

    $model = $this->_getModel();
    $this->view->entries = $model->fetchEntries();

    // Read remote feed
    try
    {
    $rss = Zend_Feed::import(‘http://newsrss.bbc.co.uk/rss/sportonline_uk_edition/football/rss.xml’);
    }
    catch (Zend_Feed_Exception $e)
    {
    // feed import failed
    echo “Exception caught importing feed: {$e->getMessage()}n”;
    exit;
    }

    // Initialize the channel data array
    $channel = array(
    ‘title’ => $rss->title(),
    ‘email’ => $rss->email(),
    ‘comment’ => $rss->comment(),
    ‘items’ => array()
    );

    // Loop over each item and store relevant data
    foreach ($rss as $item) {
    $channel['items'][] = array(
    ‘title’ => $item->title(),
    ‘email’ => $item->email(),
    ‘comment’ => $item->comment()
    );
    }

    // Pass to view
    $this->view->entries = $channel['items'];
    }

    }

    Im getting an error message saying it cant find my model ForumForm now. The include path is correct as shown before. How can I solve this?

    Dan

  152. The server I am using needs to have the current application in the root directory. Therefore, I cannot put your demo into the root (index.php). Is there another suggestion for folks who are learning about ZF on a server already configured?

    Also, my client uses IIS on a Windows system. Do you have a suggestion or link to installing ZF on Windows based servers?

    Todd Cary

  153. Hello Rob,

    I’m using XAMPP and I still have problem while trying to get the data from the table, Apache still crashes after a while.

    Is it because of PDO and PDO_MYSQL PHP extensions? if yes, how to install them, is it enough to just modify php.ini, or other process must be done?

    Beside this, I like your tutorial, without it I wouldn’t be able to start using ZEND, Thanks a lot.

  154. At the top of this tutorial it says “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.”

    *Where* do I set this? I can get to my index page and any other actions within it, but when I create other controllers I can’t get to them (404).

    I have looked through my httpd.conf file and set every instance of AllowOverride to All but it’s still not working.

    Is there a setting to change in my htaccess file?

    Thanks.

  155. Hi all, Ive had many problems using xampp with this tutorial, I recomend using wamp.

    appart from having a less buggy interface all my php_PDO and mod_rewrite problems evaperated and the tute works with no playing around.

    thanks rob this tutorial rocks.

    Best regards,
    Simon

  156. Hi..Im having probs with the css part.Its not getting included.Can anyone suggest wt th prob is..

  157. Hello Rob,
    Thankyou for putting together such a simple and easy to understand tutorial – this is by far the best tutorial to get started on the Zend framework.

    Are there any other advanced Zend framework tutorials that you have written like maybe something on the login authentication part? If so please let me know where I can find it.

    Once again thankyou so much for putting this one together – really appreciate it.

    –Gubloo
    Hard work never killed anybody, but why take a chance

  158. Hi Rob,
    Thanks a lot for the link. I really liked the way you explain stuff and have decided to buy the Zend Framework in Action book.

    I just downloaded the souce code from the Manning website for this book and I found a lot of inconsistency in the directory structures. Like one thing that stood out was in some chapters – the directory is named as “public” but in the readme.txt – its mentioned as web_root.

    Just wanted to bring it to your attention.

    Excited to read your book.
    Thanks again.

  159. Thank you Rob!

    Would it be possible to add a reference in the tutorial to make sure to install the PDO extension, just for those of us who don’t realize that it’s not automatically installed ;) ? http://nl3.php.net/manual/en/pdo.installation.php

    One other thought … I was watching the “Zend Framework – Authentication” Webinar and noticed a very different way of “bootstrapping” the application. The author, Darby Felton, used an “application wrapper” class instead of a procedural php script. Do you have any thoughts on which method to use and when?

  160. dan_nl,

    I will bear in mind for next version :)

    Regarding bootstrapping, I recommend Zend_Application for when ZF 1.8 is released!

    Regards,

    Rob…

  161. Anyway thank’s to share article. I hope this tutorial can help me building application using Zend. I was search many tutoial on web, but no one work at Zend 1.7.8.

  162. Hey Rob,

    I’ve been going through the tutorial in more depth and began to wonder about a few items that “could” be implemented in a different way. I’m definitely not an expert at this yet :) and would appreciate your feedback …

    1. Since registerAutoload() is set, is it not good practice to set the registry with this?

    Zend_Registry::set(‘config’, $config);

    instead of:

    $registry = Zend_Registry::getInstance();
    $registry->set(‘config’, $config);

    2. In regards to the db set-up, to actually use the registry settings rather than the $config instance?

    $db = Zend_Db::factory(Zend_Registry::get(‘config’)->db);
    Zend_Db_Table::setDefaultAdapter($db);

    instead of:

    $db = Zend_Db::factory($config->db);
    Zend_Db_Table::setDefaultAdapter($db);

    3. To make sure we clean-up the variables?

    unset($config, $registry[if we use it], $db, $frontController);

    4. And then dispatch the Front Controller with?

    Zend_Controller_Front::getInstance()->dispatch();

  163. Dan_nl,

    You are seeing effects of evolving the tutorial since pre-1.0 :)

    1. Yes. Zend_Registry::set('config', $config); is simpler and does the same job.

    2. I disagree. Why use the additional function call when you already have the $config object around though?

    3. Yes, but it’s a better idea to just limit the scope using a bootstrap() function or class.

    4. Moot, if you’ve limited the variables to the local scope of class in 3.

    Regards,

    Rob…

  164. 2. I reckon it’s a toss-up ;) I tried it out this way because it seems that the Zend_Registry really isn’t being used by the application other than being set … at least I didn’t notice it being used anywhere else, so I tried applying it and found this code worked.

    Thanks again,
    Dan

  165. When I type in http://localhost/~me/zf-tutorial/public/ it gives me a 404 not found error. However when I type in the exact URL including index.php at the end, the tutorial page shows up with ‘My Albums’.

    I’ve had my apache/php configuration working so far on OS 10.5 and double checked with this great tutorial:
    http://danilo.ariadoss.com/2007/12/16/how-to-setup-apache-php-mysql-on-mac-os-x-105-leopard/

    After this and double checking the .htmaccess file, I still can’t get index.php to show up. I can’t find an answer to the prob here so I’d appreciate someone helping out!

  166. http://localhost/~me/zf-tutorial/public/index.php

    works fine though, so it has no problems with the ~. That’s how Mac’s work unless you assign a virtual host. I didn’t want to go through the trouble of setting up a virtual host for this tutorial though.

    The question is why it’s not recognizing the index when it’s not in the url.

  167. Benj_em,

    I meant that it’s to do with mod_rewrite and a user home directory. A quick google suggests that you need to do something like:

    RewriteBase /~me/zf-tutorial/public/

    in your .htaccess file.

    Regards,

    Rob…

  168. hey that worked! I guess I didn’t know what to google because I got a bunch of other confusing things. I’m such a gui person anyway this hosts thing is very confusing. It’s good to have someone just point it out.

    If you have the inclination, an explanation of how that worked would be awesome, but thanks anyway!

  169. After completing the steps on page 14, I’m getting this error:
    Parse error: syntax error, unexpected T_VARIABLE in /Users/me/Sites/zf-tutorial/public/index.php on line 16

    It has something to do with the config.ini file maybe? The table exists on localhost and I can browse it and everything. Any ideas?

  170. thanks man fixed it. I copied those lines straight out of the pdf but have to clean out little tab spaces. I guess I accidentally knocked something out!

  171. Thank you very much for this tutorial, just started with it. I am looking for good tutorials for this framework and not just some code saying to do this or that.

    Do you have more good tutorials or know some good ones?

  172. Am I crazy or is there no header.phtml or footer.phtml details in this tutorial? Those elements are necessary for the next tutorial on using a login form.

  173. I had this working perfectly by keeping ‘index.php’ in the ‘public’ folder. But I wanted to move .htaccess to the zf-tutorial root folder so that I don’t have to load ‘http://localhost/zf-tutorial/public/ in the browser.

    Now that I’ve moved it and changed Rewrite rule to this:
    RewriteRule .* /public/index.php

    It’s giving me a 404 error. I find the whole .htaccess and index.php file location thing very confusing! What should the path be? Should index.php be in the root dir and not in ‘public’?

  174. Hi Rob,

    I tried the tutorial, and got most of it working. One problem was the edit-form which didn’t work with the code you provided. I’m not an experienced php-developer, so it took some time. Changing the code to the following did the trick:

    $id = (int)$this->_request->getParam(‘id’);
    if ($id > 0)
    {
    $albums = new Albums();
    $this->view->album = $albums->fetchRow(‘id=’.$id);
    }

    This is the else-part (handling the get-request) of the editAction() function in IndexController.php. This should probably be handled using a Zend-form, but that’s another challenge (for me at least).

    (Maybe someone else noticed this in the comments above; I didn’t read all comments…)

  175. Hi,

    the application is chrashing my apache!!
    then i downloaded the .zip, and the sorce app is killing Apache to :(

    im using Vista ultimate 64 php 5.2.8, mysql 5.1.30, apache 2.2.11, PDO support enabled

  176. Kriss,

    You’re going to have to provide a little more detail as to what you mean… Personally, I’d check that you have removed the semicolon in front of the extension=mod_rewrite.dll line in your httpd.conf file.

    Regards,

    Rob…

  177. mod_rewrite is enabled. i think the problem is in Zend_Db_Table::setDefaultAdapter($db), whwn i comment this line i only get exception ‘Zend_Db_Table_Exception’ with message ‘No adapter found for Albums’, if not // the apache stops working.

Comments are closed.