所以我对很多这方面都是新手。绝对是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,
]);
数据本身以字节形式保存在Postgres表中。
我很确定我的头脑中遗漏了什么。提前感谢您的帮助。
假设ORM返回某种类型的图片对象,则对变量$picture
执行var_dump()
,并查看在不知道picture
表结构的情况下可用的字段。
您的问题正如错误所示,$picture
是一个对象,您的模板系统需要一个字符串(或转换为字符串的东西)。您想要传入想要显示的$picture
对象的字符串属性:
$params = array_merge(
get_base_params('account', 'Edit Profile'),
[
'picture' => $picture->some_property,
]);
ORM库可能没有找到图片并返回其自身或某个事物的实例。