gpt4 book ai didi

php - 覆盖模型 tostring 方法

转载 作者:行者123 更新时间:2023-12-04 00:35:59 26 4
gpt4 key购买 nike

我想知道是否可以覆盖 tostring() Laravel 4 中模型的方法。

我希望能够写echo $model;在 View 中,它以特定方式打印该对象,而不必在此模型中创建新函数。

最佳答案

找到了。只是覆盖魔法函数 __tostring()

public function __toString() {
return "Object toString";
}

关于php - 覆盖模型 tostring 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24509278/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com