1
中調用在我的應用程序中,我已經建立了數據庫連接。現在我想切換表格,我不斷收到以下錯誤切換表的zend db錯誤可捕獲的致命錯誤:傳遞給__construct()的參數1必須是一個數組,對象給定,在
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));
其錯誤消息的一部分,你不具體瞭解? – hakre
它需要傳遞數組而不是對象。我第一次訪問一個表它傳遞一個對象,爲什麼它第二次不起作用?以下是我的seismicfile模型'公共職能__construct(數組$選項= NULL) \t { \t \t如果(is_array($選項)){ \t \t \t $這個 - > setOptions($選項); \t \t} \t}' – shorif2000
變量不是常量,它們可以隨時間改變它們的值。 – hakre