yatta-tecnologia/presenter
最新稳定版本:0.1.0
Composer 安装命令:
composer require yatta-tecnologia/presenter
包简介
Presenters
关键字:
README 文档
README
Install
Pull this package in through Composer.
{
"require": {
"yatta-tecnologia/presenter": "0.1.*"
}
}
Usage
The first step is to store your presenters somewhere - anywhere. These will be simple objects that do nothing more than format data, as required.
Here's an example of a presenter.
use Yatta\Presenter\Presenter;
class UserPresenter extends Presenter {
public function fullName()
{
return $this->first . ' ' . $this->last;
}
public function accountAge()
{
return $this->created_at->diffForHumans();
}
}
Next, on your entity, pull in the Yatta\Presenter\PresentableTrait trait, which will automatically instantiate your presenter class.
Here's an example - maybe a Laravel User model.
<?php
use Yatta\Presenter\PresentableTrait;
class User extends \Eloquent {
use PresentableTrait;
protected $presenter = 'UserPresenter';
}
That's it! You're done. Now, within your view, you can do:
<h1>Hello, {{ $user->present()->fullName }}</h1>
Notice how the call to the present() method (which will return your new or cached presenter object) also provides the benefit of making it perfectly clear where you must go, should you need to modify how a full name is displayed on the page.
Have fun!
Valdinei F. Lima
统计信息
- 总下载量: 730
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-01-01