我一直在尝试创建一个Zend\Db\TableGateway实例,但是无法正确地实现它。这就是我的module.php
use Question\Model\QuestionsTable;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;
//other statements and then getServiceConfig()
public function getServiceConfig()
{
return array(
'factories' => array(
'Question\Model\QuestionsTable' => function($sm) {
$tableGateway = $sm->get('AlbumTableGateway');
$table = new QuestionsTable($tableGateway);
return $table;
},
'AlbumTableGateway' => function ($sm) {
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new QuestionsTable());
return new TableGateway('questions', $dbAdapter, null, $resultSetPrototype);
},
),
);
}这是我的QuestionsTable.php文件:
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;
}
}这就是我遇到的错误:Catchable fatal error: Argument 1 passed to Question\Model\QuestionsTable::__construct() must be an instance of Zend\Db\TableGateway\TableGateway,none given.
提前谢谢。
发布于 2013-12-10 19:21:34
嗨,我想你应该把表类和原型类分开。
作为解决方案,您可以在问题\模型\问题中添加另一个类问题,并将其用作原型。
$resultSetPrototype->setArrayObjectPrototype(new Questions()); //instead of QuestionsTable你可以用数据库和模型描述的同样的方式来做这件事
https://stackoverflow.com/questions/20501038
复制相似问题