异常信息:消息:找不到Model_Bug的适配器

时间:2012-07-25 09:38:22

标签: zend-framework zend-db

我会说实话,Zend现在给了我很多麻烦,但我想我们都必须从某个地方开始,我正在快速学习。

我正在使用Apress的书“Pro Zend Framework Techniques”来学习如何使用Zend,但昨晚的命中和错误是我无法解决的。谷歌搜索并睡了一晚,我仍然无处可去。这是错误:

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',
)  

一般来说,这个错误的原因是什么?我该如何解决呢?

相关文件如下,如果需要更多信息,我会发布。

我的application.ini文件:

[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

自举:

<?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;
    }
}

错误模型:

<?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控制器:     

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
    }


}

1 个答案:

答案 0 :(得分:1)

您的适配器未初始化,因为您的application.ini文件中存在拼写错误

recources.db.adapter = "Pdo_Mysql"

应该是

resources.db.adapter = "Pdo_Mysql"