sbstjn/sliphp
Composer 安装命令:
composer require sbstjn/sliphp
包简介
Atomic view and layout engine for PHP 5.4 and above
README 文档
README
Atomic view and layout engine for PHP 5.4 and above.
Usage
To use SliPHP please configure the global constant SLIPHP_VIEWS and set it to the directory where your views, layouts and blocks are located.
Installation
composer require sbstjn/sliphp
Basics
As mentioned above, just configure the needed constant and you are good to go …
define ('SLIPHP_VIEWS', '/var/www/views/');
The folder structure inside your SLIPHP_VIEWS path should look something like this:
/var/www/views/index.php (View)
/var/www/views/layouts/default.php (Layout)
/var/www/views/blocks/header.php (Block)
Views
It's that simple to render a view from your SLIPHP_VIEWS folder:
$view = new SliPHP\View('index'); die($view);
Your index.php could look like this:
<strong>Hi!</strong>
Layouts
Of course you want to have a separate file for your layout, which will be wrapped around your index view:
$layout = new SliPHP\Layout('default'); $layout->body(new SliPHP\View('index')); die($layout);
Your layouts/default.ph file could look like this:
<!DOCTYPE html> <html lang="en-US"> <head> <title>SliPHP</title> <meta charset="utf-8" /> </head> <body><?=$view->body()?></body> </html>
As you might guess, the content of your view gehts inserted inside the body tag. Woho, Magic …
Blocks
For sure SliPHP supports loading single files and have them rendered into your views and layouts. We call them blocks, just use the ->block() method for loading them:
<!DOCTYPE html> <html lang="en-US"> <head> <title>SliPHP Example</title> <?=$view->block('header')?> </head> <body><?=$view->body()?></body> </html>
Your blocks/header.php could look like this:
<meta charset="utf-8" />
Blocks can load other blocks as well, so feel free to move your styles and script to separate files for example:
<meta charset="utf-8" /> <?=$view->block('styles')?> <?=$view->block('script')?>
Apply
If you want to apply a function or a list of functions to a data object, you can use the $view->apply function to modify your data:
<strong><?=$view->apply('KATZE', 'ucfirst|strtolower')?><?=$view->apply('KATZE', 'strtolower|ucfirst')?></strong>
Will be rendered into:
<strong>katzeKatze</strong>
Helper
There is built in support for custom helper functions in SliPHP, just define your helpers like this:
$view = new SliPHP\View('index'); $view->helper('strong', function($value) { return '<strong>' . $value . '</strong>'; });
And call them inside your views with:
<?=$view->strong('hi')?>
You can for example use this to easily include your stylesheets:
$view->helper('css', function($file) { return '<link rel="stylesheet" href="' . $file . '" type="text/css" charset="utf-8" />'; });
Locals
Of course you can pass data to your views, SliPHP calls them Locals …
$view = new SliPHP\View('index'); $view->set('foo', 'value');
You can access all your data using the $data variable inside your layouts, views and of course blocks:
<?=$data->foo?>
It's also possible to share locals between your layout and your views:
$layout = new SliPHP\Layout('default'); $layout->set('foo', 'value'); $layout->body('index');
Inside your index view you can now easily access to layout's locals:
<?=$data->foo?>
Change log
Please see CHANGELOG for more information what has changed recently.
Testing
$ composer test
Contributing
Please see CONTRIBUTING and CONDUCT for details.
Security
If you discover any security related issues, please email mail@sbstjn.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
sbstjn/sliphp 适用场景与选型建议
sbstjn/sliphp 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 23 次下载、GitHub Stars 达 1, 最近一次更新时间为 2015 年 10 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 「template」 「view」 「layout」 「engine」 「render」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sbstjn/sliphp 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sbstjn/sliphp 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sbstjn/sliphp 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
Shoot aims to make providing data to your templates more manageable
Illuminate View for Morningmedley.
Blade template for Kirby
Simple ASCII output of array data
View5 is a version of Blade Templates for the Mvc5 Framework
统计信息
- 总下载量: 23
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-10-06