切换表上的zend db错误可捕获的致命错误:传递给__construct()的参数1必须是一个数组,给定的对象,调用

时间:2012-06-28 11:23:51

标签: php zend-framework centos zend-db zend-db-table

在我的应用程序中,我已经设置了数据库连接。现在我想切换表格,我不断收到错误

Catchable fatal error: Argument 1 passed to Application_Model_PgeSeismicFile::__construct() must be an array, object given, called in /opt/eposdatatransfer/application/models/PgeSeismicFileMapper.php on line 58 and defined in /opt/eposdatatransfer/application/models/PgeSeismicFile.php on line 10 

我有两个表的两个模型。我尝试访问第二个表时遇到错误。访问和设置第一个表很好,我也这样做。以下是我如何切换表格。

private $_dbTable = null;

    public function setDbTable($dbTable, $path = false)
    {
        $project = $_REQUEST['username'];

        $filename = $path . "PSDB.db"; //APPLICATION_PATH . "/data/db/".$project."/PSDB.db";

        if (!file_exists($filename)) {
            //$this->_redirect('/');
            // need to redirect and pass eror message for user
            throw new Exception("File does not exist");
        }

        try{
            //exit("3");
            $dbAdapter = Zend_Db::factory("pdo_sqlite", array("dbname"=> $filename));
        }catch (Zend_Db_Adapter_Exception $e) {
            // perhaps a failed login credential, or perhaps the RDBMS is not running
            var_dump($e);
            exit("1");

        } catch (Zend_Exception $e) {
            // perhaps factory() failed to load the specified Adapter class
            var_dump($e);
            exit("2");
        }

        if (is_string($dbTable)) {
            print_r($dbAdapter);
            $dbTable = new $dbTable($dbAdapter);
            $dbTableRowset = $dbTable->find(1);
            $user1 = $dbTableRowset->current();
            //var_dump($user1);
            //exit("hello");
            //$row = $user1->findDependentRowset();
        }
        if (!$dbTable instanceof Zend_Db_Table_Abstract) {
            throw new Exception('Invalid table data gateway provided');
        }
        $this->_dbTable = $dbTable;
        //$session = new Zend_Session_Namespace();
        //$session->dbAdapter = $this->_dbTable;
        //var_dump($this);
        //exit();
        return $this;
    }

    public function getDbTable($path = false)
    {
        if (null === $this->_dbTable) {
            $session = new Zend_Session_Namespace();
            //$this->setDbTable('Application_Model_PgeSeismicFile',$path);
            $this->dbTable = new Application_Model_PgeSeismicFile($session->dbAdapter);
        }
        return $this->_dbTable;
    }

这行错误

$this->dbTable = new Application_Model_PgeSeismicFile($session->dbAdapter);

在我的会话中,我正在存储:

$dbAdapter = Zend_Db::factory("pdo_sqlite", array("dbname"=> $filename));

1 个答案:

答案 0 :(得分:0)

试试这个

$dbAdapter = Zend_Db::factory("pdo_sqlite", array("dbname"=> $filename));

Zend_Db_Table::setDefaultAdapter($dbAdapter);

$this->dbTable = new Application_Model_PgeSeismicFile;