ZF2 aka Apigility更新SQL数据库条目

时间:2014-10-04 20:00:16

标签: mysql zend-framework2 apigility

我正在尝试使用基于ZF2的框架Apigility更新数据库中的行。

我看到该行存在,检索它的内容,并更新对象..但是当我尝试$table->update($arrayOfRowData);时,我得到一个例外;

有关如何使用Update()的文档有点稀疏..我是否需要将where=子句放入?我是否需要将where子句与所有表的主键匹配?(主键使用3列)

try {
    // if an entry already exists, update it
    $existingRow = $this->currentEntryExists($ff_user_id, $subvalue);
    if($existingRow != false ){

        $fieldType = $this->transformer->mapField($key);
        $existingRow[$fieldType] = $subvalue['value'];
        $this->update($existingRow, $where = array('field_id' => $existingRow['field_id'], 'user_id' => $user_id, 'field_date' => $subvalue['dateTime']));
    }else{
        $fieldType = $this->transformer->mapField($key);
        $dataArray = array('user_id' => $user_id,
                           'field_date' => $subvalue['dateTime'],
                           $fieldType => $subvalue['value']);
        $result = $this->insert($dataArray);
    }
} catch (Exception $e) {
    $logger = $this->getServicesLogger();
    $logger->err($e);
    throw $e;
}

抛出异常:

"type": "http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html",
"title": "Internal Server Error",
"status": 500,
"detail": "Invalid magic property access in Zend\\Db\\TableGateway\\AbstractTableGateway::__get()"

1 个答案:

答案 0 :(得分:0)

结果我试图使用类中不存在的字段,这就是Zend Framework报告它的方式。

protected function getServicesLogger()
{
    if (!$this->logger) { //this field didn't exist
        $this->logger = new ApiLogger(get_class($this));
    }
    return $this->logger;
}