class ORM 的对象无法转换为字符串 <img src

Object of class ORM could not be converted to string <img src

所以我对其中的很多内容都是陌生的。绝对 PHP 和 idorm。我进行了广泛的搜索,但没有看到这个特定问题的答案。

class ORM 的对象无法转换为字符串。

在 $picture 的 php 代码处弹出 Slim 错误。

这是我的 Html 视图

<div class="profile-left">
  <div class="profile-image">
    <img src="<?= empty($picture) ? '/static/images/profile-default.png' : $picture ?>"/>
      <i class="fa fa-user hide"></i>
  </div>
  <div class="m-b-10">
    <button class="btn btn-warning btn-block btn-sm" type="button" id="change_picture" data-toggle="modal" href="#change-picture-modal">Change picture</button>
  </div>
</div> 

这是 $picture 在另一个文件中的路径

$picture = ORM::for_table('picture')
    ->where('picture_gallery_id', $user->account_id)
    ->where('name', $user->account_id . ':profile')
    ->find_one();

$params = array_merge(
    get_base_params('account', 'Edit Profile'),
    [
        'picture' => $picture,
    ]);

数据本身作为 bytea 保存在 Postgres table 中。

我很确定我的新手缺少了一些东西。预先感谢您的帮助。

假设 ORM returns 是某种类型的图片对象,执行 var_dump() 变量 $picture 并查看可用的字段(如果您不知道其结构) picture table.

您的问题与错误指示的完全一样,$picture 是一个对象,您的模板系统需要一个字符串(或转换为字符串的内容)。你想传入你想要显示的 $picture 对象的字符串 属性:

  $params = array_merge(
get_base_params('account', 'Edit Profile'),
[
    'picture' => $picture->some_property,
]);

ORM 库有可能没有找到图片并返回其自身或某物的实例。