Zend framework2 ZF2 TableGateway不';插入一行时t工作

Zend framework2 ZF2 TableGateway不';插入一行时t工作,zend-framework2,tablegateway,Zend Framework2,Tablegateway,在DB中插入一行时发生了一个致命错误。我不明白发生了什么,我读了一些博客,但没有解决方案,我的代码与Evan在他的博客中公布的示例相同 我的模范班 class CommentTable { protected $_commentTableGateway; protected $_hydratator; protected $_resultSet; public function __construct($adapter) { $thi

在DB中插入一行时发生了一个致命错误。我不明白发生了什么,我读了一些博客,但没有解决方案,我的代码与Evan在他的博客中公布的示例相同

我的模范班

class CommentTable 
{
    protected $_commentTableGateway;
    protected $_hydratator;
    protected $_resultSet;

    public function __construct($adapter)
    {
        $this->_hydratator           = new \Zend\Stdlib\Hydrator\ClassMethods;
        $rowObjectPrototype = new Comment();
        $this->_resultSet          = new \Zend\Db\ResultSet\HydratingResultSet($this->_hydratator, $rowObjectPrototype);
        $this->_commentTableGateway =  new TableGateway('comments', $adapter, null, $this->_resultSet );
    }   
    public function fetchAll() 
    {
        return $this->_commentTableGateway->select();
    }

    public function saveComment(Comment $comment)
    {  
        $id = (int)$comment->getId();
        if ($id == 0) {
           $this->_commentTableGateway->insert($this->_hydratator->extract($comment));//this fails
        } else {
            if ($this->getComment($id)) {
                $this->_commentTableGateway->update($data, array('id' => $id));
            } else {
                throw new \Exception('El comentario que queire editar no exite');
            }
        }
    }

    public function getComment($id)
    {
        $id  = (int) $id;
        $rowset = $this->_commentTableGateway->select(array('id' => $id));
        $row = $rowset->current();
        if (!$row) {
            throw new \Exception("Could not find row $id");
        }
        return $row;
    }
}
</code>
<code>
在模块类中:

//a factory in service manager
'Comment\Model\CommentTable' =>  function($sm) {
        $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
        $table = new CommentTable($dbAdapter);
        return $table;
},
</code>    
<code>
我的控制器:

public function getCommentTable() { if (!$this->_commentTable) { $sm = $this->getServiceLocator(); $this->_commentTable = $sm->get('Comment\Model\CommentTable'); } return $this->_commentTable; } </code>
公共函数getCommentTable() { 如果(!$this->\u注释表){ $sm=$this->getServiceLocator(); $this->_commentTable=$sm->get('Comment\Model\commentTable'); } 返回$this->\u commentTable; } 我得到了这个错误:

可捕获的致命错误:stdClass类的对象无法转换为第258行D:\xampp\htdocs\haystack\vendor\zendframework\zendframework\library\Zend\Db\Adapter\Driver\Pdo\Statement.php中的字符串

我知道错误的类型(“stdClass无法转换为字符串”),但我不明白发生了什么

谢谢你的帮助


亲切的问候。

希望这能帮到你。这是我的餐桌

class Domains extends AbstractTableGateway
{
    public function __construct($adapter)
    {
        $this->table = 'domains';

        $this->adapter = $adapter;

        $this->initialize();
    }
}
下面是我如何插入数据的:

$this->getTableDomains()->insert(array(
    'companyid' => $params['companyid'],
    'domain_id' => $result->id,
    'name'      => $name,
    'type'      => strtoupper($params['type']),
    'content'   => strtolower($params['content']),
    'ttl'       => $ttl,
    'prio'      => $prio
));

嗨,非常感谢。我发现了错误,在最后一刻在实体模型中添加了一个变量,在其get方法中没有控制。。