Create the Front Controller to complete a Zend Framework tutorial

Posted on 2009-04-17
Medium Priority
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
  • 2
LVL 49

Accepted Solution

Roonaan earned 2000 total points
ID: 24179726
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

ID: 24181976
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

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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month15 days, 19 hours left to enroll

850 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