0

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

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

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

这是在我的 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 表中。

我很确定我在我的菜鸟风格中遗漏了一些东西。预先感谢您的任何帮助。


假设 ORM 返回某种类型的图片对象,如果您不知道表的结构,请执行var_dump()变量并查看可用的字段。$picturepicture

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

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

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

4

1 回答 1

0

假设 ORM 返回某种类型的图片对象,如果您不知道表的结构,请执行var_dump()变量并查看可用的字段。$picturepicture

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

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

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

于 2016-07-25T17:19:42.143 回答