ifnot/renderable
Composer 安装命令:
composer require ifnot/renderable
包简介
Renderable is a PHP Presenter for Laravel, based on blade views for a final presentation of Eloquent models directly on your views.
README 文档
README
Renderable is a PHP Presenter for Laravel, based on blade views for a final presentation of Eloquent models directly on your views.
Installation
Simply install the package with composer.
composer require ifnot/renderable
Register the package service provider into your app.php :
'Ifnot\Renderable\RenderableServiceProvider',
How it works ?
A Renderable object is like a Presenter object but for returning views (complete or partial). If you are familiar with the Presenter pattern, you should understand easily Renderable mechanisms.
The main goal of this package is to provide witch view to use for rendering a model/property. This is very usefull if you want to include an model (or model property) in your view direcly without specifying the html witch definy him.
There are two aspects in this package :
- Property renderer
- Model renderer
Property Renderer (Basic setup)
We have a Page Model (it could be Eloquent Model) and a PageRenderer (the Renderer class assigned for Page).
Page :
use Ifnot\Renderable\RenderableTrait; class Page extends Eloquent { use RenderableTrait; public $renderer = 'PageRenderer'; }
PageRenderer :
use Ifnot\Renderable\Renderer; class PageRenderer extends Renderer { public function title() { return $this->render($this->entity->title, 'page.property.title'); } }
And then, the page.property.title view:
<h1>{{ $property }}</h1>
Now you can call $page->render()->title into a regular view of your app:
.. other stuff here ... <div> {{ $page->render()->title}} <p>This is another text, blah blah blah ...</p> </div> .. other stuff here ..
Model Renderer (Basic setup)
Now ok, you want to render your whole model by itself, without specifying each properties. We have to add some configuration into PageRenderer :
PageRenderer :
use Ifnot\Renderable\Renderer; class PageRenderer extends Renderer { public $renderable = [ 'model' => [ 'show' => 'page.model' ] ]; // ... // Here, properties declaration (like title in the previous example) // ... }
And then, the page.model view :
<div> <h1>{{ $entity->render()->title }}</h1> <p>{{ $entity->content }}</p> </div>
Now you can call $page->render() into a view :
.. other stuff here .. <article> {{ $page->render() }} </article> .. other stuff here ..
Advanced Setups
- TODO : Write some lines about property binding
- TODO : Explain display mode usage ...
ifnot/renderable 适用场景与选型建议
ifnot/renderable 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 195 次下载、GitHub Stars 达 2, 最近一次更新时间为 2014 年 11 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「view」 「model」 「render」 「eloquent」 「renderable」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ifnot/renderable 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ifnot/renderable 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ifnot/renderable 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Interfaces for web resource models and services to retrieve and create them
Illuminate View for Morningmedley.
Laravel 5 - Repositories to the database layer
Blade template for Kirby
统计信息
- 总下载量: 195
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: WTFPL
- 更新时间: 2014-11-24