【发布时间】:2015-09-28 18:21:08
【问题描述】:
我的应用程序中有许多模型。每个模型都有一些在无数地方使用的特定标记。例如,我的User 模型有一个profile_link 属性,其定义如下:
class User extends Model {
/*
* Returns the anchor tag to the users profile.
*/
public function getProfileLinkAttribute() {
// This particular markup is simple. In the actual code, the HTML
// is more complex, containing user's profile image etc.
return '<a href="' . url($this->id) . '">' . $this->name . '</a>';
}
}
对于许多模型有许多这样的访问器,它们返回相似的代码 sn-ps。这种方法的问题在于它让我在模型中编写 HTML 标记。有没有标准的方法来解决这个问题?
【问题讨论】:
-
您可以探索
presenters,这样您就可以拥有BasePresenter。其他选项也是 html 宏。
标签: model-view-controller laravel-5