mysql - ZF2 aka Apigility 更新 SQL 数据库条目

标签 mysql zend-framework2 laminas-api-tools

我正在尝试使用基于 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()"

最佳答案

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

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

关于mysql - ZF2 aka Apigility 更新 SQL 数据库条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26196636/

相关文章:

php - Symfony 2.8 清除缓存并超时

zend-framework2 - ZF2验证-如果另一个元素不为空,则为必填字段

javascript - ZF2 headScript 包含两次相同的文件

php - 限制 Apigility 中的结果

php - 尝试根据上一个表的选择从 2 个不同的表中获取多个 COUNT(id)

php - 在 while 循环中组合两个 SQL 查询

sql - ms-access 列表框怪异(内存问题?)

php - Zend\Db\ResultSet\ResultSet 对象在哪里存储检索到的数据?

php - Apigility 子路由未获取父参数

php - 如何为具有多个版本的 Apigility ZF2 应用程序设置 PHPUnit?