【问题标题】:Fatal error: Uncaught exception 'Zend_Db_Table_Exception'致命错误:未捕获的异常“Zend_Db_Table_Exception”
【发布时间】:2014-04-08 15:36:33
【问题描述】:

我正在使用 zend1.12。我将 index.php 从 public 放置到根文件夹并更改了配置,之后它抛出了错误。

我收到以下错误,所有配置看起来都很好。

Fatal error: Uncaught exception 'Zend_Db_Table_Exception' with message 'No adapter found for Application_Model_Content' in /var/www/html/library/Zend/Db/Table/Abstract.php:756 Stack trace: #0 /var/www/html/library/Zend/Db/Table/Abstract.php(740): Zend_Db_Table_Abstract->_setupDatabaseAdapter() #1 /var/www/html/library/Zend/Db/Table/Abstract.php(269): Zend_Db_Table_Abstract->_setup() #2 /var/www/html/library/Zend/Db/Table.php(77): Zend_Db_Table_Abstract->__construct(Array) #3 /var/www/html/application/views/scripts/common/topnav.phtml(2): Zend_Db_Table->__construct() #4 /var/www/html/library/Zend/View.php(108): include('/var/www/html/a...') #5 /var/www/html/library/Zend/View/Abstract.php(888): Zend_View->_run('/var/www/html/a...') #6 /var/www/html/application/layouts/scripts/front_header.phtml(29): Zend_View_Abstract->render('common/topnav.p...') #7 /var/www/html/library/Zend/View.php(108): include('/var/www/html/a...') #8 /var/www/html/library/Zend/View/Abstract.php(888): Zend_View->_run('/var/www/html/a...') #9 /var/www/ in /var/www/html/library/Zend/Controller/Plugin/Broker.php on line 336

下面是 application/configs/application.ini 文件

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

resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"

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

resources.session.remember_me_seconds = 864000

[staging : production]

[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.db.adapter = "PDO_MYSQL"
resources.db.params.host = "localhost"
resources.db.params.username = "root"
resources.db.params.password = "root123"
resources.db.params.dbname = "labs"
resources.db.isDefaultTableAdapter = true

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

resources.db.params.profiler.enabled = true
resources.db.params.profiler.class = Zend_Db_Profiler_Firebug

/index.php

<?php
date_default_timezone_set('Indian/Mahe');
// Define path to application directory
define('BASE_PATH', realpath(dirname(__FILE__)));

defined('APPLICATION_PATH')
   || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/application'));

// Define application environment
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'testing'));


// Include path
set_include_path(
    BASE_PATH . '/library' 
   /*. PATH_SEPARATOR . '../Zend' */   
    . PATH_SEPARATOR . get_include_path()
);

/** Zend_Application */
require_once 'Zend/Application.php';
// Create application, bootstrap, and run

$application = new Zend_Application(
    APPLICATION_ENV,
    APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()
            ->run();
Zend_Db_Table::getDefaultAdapter();

/application/bootstrap.php

<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{    
    protected function _initMyDb() {

    $this->bootstrap('db');
    $resource = $this->getPluginResource('db');
    $db = $resource->getDbAdapter();

   //$db->query('SET CHARACTER SET \'UTF8\'');
}

protected function _initRegistry()
{
    $this->bootstrap('db');
    $db = $this->getResource('db');
   // $db->query("SET NAMES 'utf8'");
}
}

【问题讨论】:

  • /var/www/html/application/views/scripts/common/topnav.phtml(2): Zend_Db_Table-&gt;__construct() 为什么会出现在视图中?
  • 我写这个是为了从模型中访问函数
  • 文件夹文件夹中的 index.php 也一样

标签: php mysql .htaccess zend-framework


【解决方案1】:

您将适配器设置为[testing: production]

[testing : production]
...
resources.db.adapter = "PDO_MYSQL"
resources.db.params.host = "localhost"
resources.db.params.username = "root"
resources.db.params.password = "root123"
resources.db.params.dbname = "labs"
resources.db.isDefaultTableAdapter = true

你有没有输入你的.htaccessSetEnv APPLICATION_ENV testing
或者这是一个错误,你应该在[production]驱逐出境

【讨论】:

    猜你喜欢
    • 2014-08-26
    • 2013-07-07
    • 2015-06-10
    • 2015-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多