Search code examples
zend-frameworkzend-db

Exception information: Message: No adapter found for Model_Bug


I'll be honest, Zend is giving me a lot of headaches at the moment, but I guess we all have to start somewhere and I'm learning fast.

I am using the Apress book 'Pro Zend Framework Techniques' to learn how to use Zend, but hit and error last night which I couldn't solve. Having Googled around and slept on it for a night I'm still getting nowhere. Here's the error:

An error occurred
Application error
Exception information:
Message: No adapter found for Model_Bug
Stack trace:
#0 /home/www-data/zend.danielgroves.net/htdocs/library/Zend/Db/Table/Abstract.php(739): Zend_Db_Table_Abstract->_setupDatabaseAdapter()
#1 /home/www-data/zend.danielgroves.net/htdocs/library/Zend/Db/Table/Abstract.php(268): Zend_Db_Table_Abstract->_setup()
#2 /home/www-data/zend.danielgroves.net/htdocs/application/controllers/BugController.php(29): Zend_Db_Table_Abstract->__construct()
#3 /home/www-data/zend.danielgroves.net/htdocs/library/Zend/Controller/Action.php(516): BugController->submitAction()
#4 /home/www-data/zend.danielgroves.net/htdocs/library/Zend/Controller/Dispatcher/Standard.php(295): Zend_Controller_Action->dispatch('submitAction')
#5 /home/www-data/zend.danielgroves.net/htdocs/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#6 /home/www-data/zend.danielgroves.net/htdocs/library/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch()
#7 /home/www-data/zend.danielgroves.net/htdocs/library/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#8 /home/www-data/zend.danielgroves.net/htdocs/public/index.php(26): Zend_Application->run()
#9 {main}  
Request Parameters:
array (
  'controller' => 'bug',
  'action' => 'submit',
  'module' => 'default',
  'author' => 'Daniel',
  'email' => 'someemail@googlemail.com',
  'date' => '12-12-2012',
  'url' => 'sadflj.asd.sd',
  'description' => 'sdfoi',
  'priority' => 'low',
  'status' => 'new',
  'submit' => 'Submit',
)  

Generally speaking, whats the cause of this error? How do I need to go about solving it?

Relevant files are below, if anymore information is required shout and I'll post it.

My application.ini file:

[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0

resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"

recources.db.adapter = "Pdo_Mysql"
resources.db.params.host = "localhost"
resources.db.params.username = ""
resources.db.params.password = ""
resources.db.params.dbname = "zf_cms"
resoucres.db.isDefaultTableAdapter = true

[staging : production]

[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1

Bootstrap:

<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    protected function _initView()
    {
        // Initialise view
        $view = new Zend_View();
        $view->doctype('XHTML1_STRICT');
        $view->headTitle('Zend CMS');
        $view->skin = 'blues';

        // Add it to the ViewRenderer
        $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper(
            'ViewRenderer'
        );
        $viewRenderer->setView($view);

        // Return it, so that it can be stored by the bootstrap
        return $view;
    }

    protected function _initAutoload()
    {
        // Add autoloader empty namespace
        $autoLoader = Zend_Loader_Autoloader::getInstance();
        $autoLoader->registerNamespace('CMS_');
        $resourceLoader = new Zend_Loader_Autoloader_Resource(array(
            'basePath'      => APPLICATION_PATH,
            'namespace'     => '',
            'resourceTypes' => array(
                'form'      => array(
                    'path'      => 'forms/',
                    'namespace' => 'Form_',
                ),
                'model'     => array(
                    'path'      => 'models/',
                    'namespace' => 'Model_'
                ),
            ),
        ));

        //Return it so that it can be stored by the bootstrap
        return $autoLoader;
    }
}

Bug Model:

<?php

class Model_Bug extends Zend_Db_Table_Abstract
{
    protected $_name = 'bugs';

    public function createBug($name, $email, $date, $url, $description, $priority, $status)
    {
        $row = $this->createRow();

        // Set the row data
        $row->author        = $name;
        $row->email         = $email;
        $dateObject         = new Zend_Date($date);
        $row->date          = $dateObject->get(Zend_Date::TIMESTAMP);
        $row->url           = $url;
        $row->description   = $description;
        $row->priority      = $priority;
        $row->status        = $status;

        // save the new row
        $row->save();

        // now fetch the id of the row you just created and return it
        $id = $this->_db->lastInsertId();
        return $id;
    }
}
?>

Bug Controller:

class BugController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        // action body
    }

    public function createAction()
    {
        // action body
    }

    public function submitAction()
    {
        $bugReportForm = new Form_BugReportForm();
        $bugReportForm->setAction('/bug/submit');
        $bugReportForm->setMethod('post');

        if ($this->getRequest()->isPost()) {
            if ($bugReportForm->isValid($_POST)) {
                $bugModel = new Model_Bug();

                // if the form is valid then create the new bug
                $result = $bugModel->createBug(
                    $bugReportForm->getValue('author'),
                    $bugReportForm->getValue('email'),
                    $bugReportForm->getValue('date'),
                    $bugReportForm->getValue('url'),
                    $bugReportForm->getValue('description'),
                    $bugReportForm->getValue('priority'),
                    $bugReportForm->getValue('status')
                );

                // if the createBug method returns a result
                // then the bug was successfully created

                if ($result)
                    $this->_foreward('confirm');
            }
        }

        $this->view->form = $bugReportForm;
    }

    public function confirmAction()
    {
        // action body
    }


}

Solution

  • Your adapter is not initialising as you have a typo in your application.ini file

    recources.db.adapter = "Pdo_Mysql"
    

    Should be

    resources.db.adapter = "Pdo_Mysql"