【问题标题】:working with Zend\Db\TableGateway\TableGateway使用 Zend\Db\TableGateway\TableGateway
【发布时间】: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


    【解决方案1】:

    试试这个:

    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);
            }
    ));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-25
      • 1970-01-01
      • 1970-01-01
      • 2014-11-14
      • 1970-01-01
      • 2014-06-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多