【发布时间】:2014-06-10 21:42:05
【问题描述】:
我正在尝试创建 Zend\Db\TableGateway 的实例以便与数据库交互,但我总是收到此错误:
Catchable fatal error: Argument 1 passed to Question\Model \QuestionsTable::__construct() must be an instance of Zend\Db\TableGateway\TableGateway, none given.
here is how am trying to implement it:...
namespace Question\Model;
use Zend\Db\TableGateway\TableGateway;
class QuestionsTable
{
public $usr_id;
public $title;
public $description;
public $status;
protected $tableGateway;
public function __construct(TableGateway $tableGateway)
{
$this->tableGateway = $tableGateway;
}
我猜想在服务管理器中实现它的方式有错误:
return array(
'factories' => array(
'Question\Model\QuestionsTable' => function($sm) {
$tableGateway = $sm->get('QuestionsTableGateway');
$table = new QuestionsTable($tableGateway);
return $table;
},
'QuestionsTableGateway' => function ($sm) {
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
$resultSetPrototype = new ResultSet();
//$resultSetPrototype->setArrayObjectPrototype(new QuestionsTable);
return new TableGateway('codepro', $dbAdapter, null, $resultSetPrototype);}
));
please help on how to go about the servicce manager..Thanks in advance
【问题讨论】:
标签: zend-framework