2013-03-14 73 views
0

您好我是新來的Zend Framework 2 和我有這行代碼的問題:Zend框架2 TableGateway getAdapter需要接口

$sql = new Sql($this->tableGateway->getAdapter()); 

如果我測試這個使用PHPUnit的我得到錯誤

Argument 1 passed to Zend\Db\Sql\Sql::__construct() must implement interface 
Zend\Db\Adapter\AdapterInterface, null given, called in C:\xampp\htdocs\zend2 
+0

此錯誤告訴您$ this-> tableGateway-> getAdapter()返回null而不是Db適配器。這意味着您首先需要在$ this-> tableGatway中引用的tableGateway對象中設置數據庫適配器。向我們提供一些關於如何從服務管理器準備數據庫適配器的更多信息,也可能是我們可以爲您提供一個在表格網關中設置適配器的解決方案。 – 2013-03-14 08:18:08

+0

我的問題現在已經修復,我沒有將屬性放在我的配置中的變量。 :) – aspnetcoreguy 2013-03-14 08:26:04

+0

這很好。如果您將此問題標記爲已關閉,那將會很好。注意 – 2013-03-14 08:32:09

回答

0

檢查是否設置了適配器。

var_dump(get_class($this->tableGateway->getAdapter()));

另外你怎麼申報$this->tableGateway

+0

這已被修復,$ this-> tableGateway來自ServiceManager。 – aspnetcoreguy 2013-03-18 08:24:01