Create the Front Controller to complete a Zend Framework tutorial

Posted on 2009-04-17
Last Modified: 2013-12-12
I am trying to work my way through a tutorial on IBM's developerworks site but the author has left out some critical code examples.

The instruction at:

Contain the following lines:
For your Front controller, you will create an index.php file in /column/htdocs/zend. This file is the only part of your application exposed to the outside world. The rest of your application is accessed through this file. The Front controller needs to do several things: load the Zend Loader (to avoid having to include every library by hand), set up your connection to the database, and dispatch requests to the appropriate application controllers; in this case, that's only the PostController.

The sample code included with the project does not include this index.php file and I am having no luck trying to put together the file he is describing.  I put together some code but I am just getting endless errors.  Below is the code for my attempt at the index.php file.

i am getting the following errors:
Fatal error: Uncaught exception 'Zend_Db_Table_Exception' with message 'No adapter found for Posts' in /Applications/MAMP/zendframework/library/Zend/Db/Table/Abstract.php:636 Stack trace: #0 /Applications/MAMP/zendframework/library/Zend/Db/Table/Abstract.php(621): Zend_Db_Table_Abstract->_setupDatabaseAdapter() #1 /Applications/MAMP/zendframework/library/Zend/Db/Table/Abstract.php(286): Zend_Db_Table_Abstract->_setup() #2 /Applications/MAMP/protected/zend/controllers/PostController.php(12): Zend_Db_Table_Abstract->__construct() #3 /Applications/MAMP/zendframework/library/Zend/Controller/Action.php(123): PostController->init() #4 /Applications/MAMP/zendframework/library/Zend/Controller/Dispatcher/Standard.php(261): Zend_Controller_Action->__construct(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http), Array) #5 /Applications/MAMP/zendframework/library/Zend/Controller/Front.php(934): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_H in /Applications/MAMP/zendframework/library/Zend/Db/Table/Abstract.php on line 636

Obviously I have not done anything to connect the database and that is the core of the problem.  Any advice would be much appreciated.

include "Zend/Loader.php"; 



// setup controller 

$frontController = Zend_Controller_Front::getInstance(); 




// run! 



Open in new window

Question by:wardjame
    LVL 49

    Accepted Solution

    The index.php is often called your "bootstrap" script. Not sure why the tutorial names it otherwise.

    Try adding the following lines before running the front controller;

    $db = Zend_Db::factory('Pdo_Mysql', array(
        'host'     => '',
        'username' => 'webuser',
        'password' => 'xxxxxxxx',
        'dbname'   => 'test'


    .. front controller code ...

    Instead of pdo_mysql you can use mysqli or other adapters to fit your requirements.


    Author Comment

    Thanks Roonan,
    This seems to have just moved me on to more errors.  I am starting to wonder if this tutorial is just junk.  I have my database setup and working fine after some tweaking of your code.  I had to add in the port number to get it connecting on my machine.

    But I am now receiving the following error:
    Fatal error: Uncaught exception 'Zend_View_Exception' with message 'script 'post/index.phtml' not found in path (../../protected/zend/views/scripts/)' in /Applications/MAMP/zendframework/library/Zend/View/Abstract.php:913 Stack trace: #0 /Applications/MAMP/zendframework/library/Zend/View/Abstract.php(816): Zend_View_Abstract->_script('post/index.phtm...') #1 /Applications/MAMP/zendframework/library/Zend/Controller/Action/Helper/ViewRenderer.php(902): Zend_View_Abstract->render('post/index.phtm...') #2 /Applications/MAMP/zendframework/library/Zend/Controller/Action/Helper/ViewRenderer.php(923): Zend_Controller_Action_Helper_ViewRenderer->renderScript('post/index.phtm...', NULL) #3 /Applications/MAMP/zendframework/library/Zend/Controller/Action/Helper/ViewRenderer.php(962): Zend_Controller_Action_Helper_ViewRenderer->render() #4 /Applications/MAMP/zendframework/library/Zend/Controller/Action/HelperBroker.php(276): Zend_Controller_Action_Helper_ViewRenderer->postDispatch() #5 /Applications/MAMP/zendframework/library/Zend/Con in /Applications/MAMP/zendframework/library/Zend/View/Abstract.php on line 913

    Author Comment

    Ok it is definitely a problem with the tutorial.  I poked around the code and found more errors.  Thanks for your help.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
    Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now