我试图创建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发布于 2014-06-10 21:31:50
试试这个:
return array(
'factories' => array(
'Question\Model\QuestionsTable' => function($sm) {
return new Question\Model\QuestionsTable();
},
'QuestionsTableGateway' => function ($sm) {
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype($sm->get('Question\Model\QuestionTable'));
$tableGateway = new TableGateway('codepro', $dbAdapter, null, $resultSetPrototype);
$table = new Question\Model\QuestionTable($tableGateway);
}
));https://stackoverflow.com/questions/20491215
复制相似问题