3

これは、データベースのデータを更新/挿入するために使用するコードです。

public function saveItem($post, $table)
    {
        unset($post['submit']);
        $this->_table = new Zend_Db_Table($table); exit;

        if (isset($post['id'])) {
            $where = $this->_table->getAdapter()->quoteInto('id = ?', $post['id']);
            $this->_table->update($post, $where);
            return $post['id'];
        } else {
            return $this->_table->insert($post);
        }
    }

何らかの理由で

$this->_table = new Zend_Db_Table($table);

エラーが発生しますが、$table = 'woningen' の場合のみで、メイン モジュールでのみ発生します。

エラーは次のとおりです。

APPLICATION ERROR
EXCEPTION INFORMATION:
Message: Argument must be of type Zend_Db_Adapter_Abstract, or a Registry key where a Zend_Db_Adapter_Abstract object is stored
STACK TRACE:
#0 D:\xampp\htdocs\makeltrent.website\library\Zend\Db\Table\Abstract.php(581): Zend_Db_Table_Abstract::_setupAdapter('woningen')
#1 D:\xampp\htdocs\makeltrent.website\library\Zend\Db\Table\Abstract.php(283): Zend_Db_Table_Abstract->_setAdapter('woningen')
#2 D:\xampp\htdocs\makeltrent.website\library\Zend\Db\Table\Abstract.php(265): Zend_Db_Table_Abstract->setOptions(Array)
#3 D:\xampp\htdocs\makeltrent.website\library\Zend\Db\Table.php(77): Zend_Db_Table_Abstract->__construct(Array)
#4 D:\xampp\htdocs\makeltrent.website\application\models\Inlog.php(109): Zend_Db_Table->__construct('woningen')
#5 D:\xampp\htdocs\makeltrent.website\application\modules\default\controllers\WoningmandjeController.php(157): Application_Model_Inlog->saveItem(Array, 'woningen')
#6 D:\xampp\htdocs\makeltrent.website\library\Zend\Controller\Action.php(516): WoningmandjeController->sendAction()
#7 D:\xampp\htdocs\makeltrent.website\library\Zend\Controller\Dispatcher\Standard.php(295): Zend_Controller_Action->dispatch('sendAction')
#8 D:\xampp\htdocs\makeltrent.website\library\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#9 D:\xampp\htdocs\makeltrent.website\library\Zend\Application\Bootstrap\Bootstrap.php(97): Zend_Controller_Front->dispatch()
#10 D:\xampp\htdocs\makeltrent.website\library\Zend\Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#11 D:\xampp\htdocs\makeltrent.website\public\index.php(26): Zend_Application->run()
#12 {main} 

4

2 に答える 2

1

エラー メッセージで説明されているように、私が最初に考えたのは、その名前の Zend_Registry キーはあるが、期待どおりの のようなオブジェクトがないということZend_Db_Adapter_Pdo_Mysqlです。ランダムな文字列はその理由で失敗することはありませんfalse. or null- を返すことになるため、_setupAdapter何もせずに単に関数から返されます.

于 2012-11-26T13:53:34.940 に答える
0

クラスの設定に問題があると思います。

Zend_Db_Tableは、テーブル名ではなく初期化するためにDBアダプターを必要とします。application.iniでアダプタをデフォルトのDBアダプタとして定義できます。

resources.db.adapter = "PDO_MYSQL"
resources.db.params.host = "host"
resources.db.params.dbname = "database"
resources.db.params.username = "user"
resources.db.params.password = "password"
resources.db.isDefaultTableAdapter = true
于 2012-11-26T08:15:41.450 に答える