0

老实说,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;
    }
}
?>

错误控制器:

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
    }


}
4

1 回答 1

1

您的适配器未初始化,因为您的 application.ini 文件中有错字

recources.db.adapter = "Pdo_Mysql"

应该

resources.db.adapter = "Pdo_Mysql"
于 2012-07-25T15:05:55.383 回答