vnphp/presenter-bundle
Composer 安装命令:
composer require vnphp/presenter-bundle
包简介
Symfony2 Presenter pattern support.
README 文档
README
Installation
composer require vnphp/presenter-bundle
You need to have git installed.
Configure
1. Add the bundle to your AppKernel.php:
<?php
$bundles = array(
new \Vnphp\PresenterBundle\VnphpPresenterBundle(),
);
2. Update your model
<?php
use Vnphp\PresenterBundle\Presenter\PresentableInterface;
use Vnphp\PresenterBundle\Presenter\PresentableTrait;
class User implements PresentableInterface
{
use PresentableTrait;
/**
* @return string service name for presenter
*/
public function getPresenterService()
{
return 'presenter.user';
}
}
3. Create presenter class
<?php
use Vnphp\PresenterBundle\Presenter\Presenter;
class UserPresenter extends Presenter
{
public function getFullName()
{
return "Full Name";
}
}
4. Add presenter service.
It is required to set scope: prototype to the definition.
services:
presenter.user:
class: 'UserPresenter'
scope: 'prototype'
Usage
Controller
<?php
$userPresenter = $this->container->get('vnphp_presenter.factory')
->getPresenter($user);
$userPresenter->getFullName();
Twig
{% set user_presenter = presenter(user) %}
{{ user_presenter.fullName }}
统计信息
- 总下载量: 13
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-11-18
