首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Zend\Db\TableGateway\TableGateway

使用Zend\Db\TableGateway\TableGateway
EN

Stack Overflow用户
提问于 2013-12-10 17:58:23
回答 1查看 203关注 0票数 0

我试图创建Zend\Db\TableGateway的实例,以便与数据库交互,但我总是收到以下错误:

代码语言:javascript
复制
     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;
                           }

我猜我在服务管理器中实现它的方式有一个错误:

代码语言:javascript
复制
                       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
EN

回答 1

Stack Overflow用户

发布于 2014-06-10 21:31:50

试试这个:

代码语言:javascript
复制
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);
        }
));
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20491215

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档