承接 slim-view/fluid 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

slim-view/fluid

Composer 安装命令:

composer require slim-view/fluid

包简介

Slim Framework view helper built on top of the TYPO3 Fluid templating engine.

README 文档

README

This is a Slim Framework view helper built on top of the TYPO3 Fluid templating engine. You can use this component to create and render templates in your Slim Framework application.

Install

Via Composer

$ composer require slim-view/fluid

Requires Slim Framework 3 and PHP 5.5 or newer.

Usage

<?php
// Create Slim app
$app = new \Slim\App();

// Fetch DI Container
$container = $app->getContainer();

// Register Fluid View helper
$container['view'] = function ($c) {
    $view = new \Slim\Views\Fluid([
        'templateRootPaths' => ['path/to/Templates/'],
        'partialRootPaths' => ['path/to/Partials/'],
        'layoutRootPaths' => ['path/to/Layouts/'],

        'singlePath' => 'path/to/Singles/',
        'cachePath' => 'path/to/fluid_cache/',
        
        'viewHelperNamespaces' => [
            'vh' => 'VendorName\\Package\\ViewHelper'
        ],
    ]);
    return $view;
};

// Renders template file "path/to/Singles/Profile.html"
$app->get('/hello/{name}', function ($request, $response, $args) {
    return $this->view->render($response, 'Profile', [
        'name' => $args['name']
    ]);
})->setName('profile');

// Run app
$app->run();

If you've outsourced your route logics to controllers and actions, your action may look like this, assuming that $this->view is instance of \Slim\Views\Fluid:

<?php
class ProfileController
{
    public function logoutAction($request, $response, $args)
    {
        $this->view->setController('Profile');
        $this->view->setAction('logout');
        $this->view->assign('name', $args['name']);
        
        // Template file loaded: path/to/Templates/Profile/Logout.html
        return $this->view->render($response);
    } 
}

In case you want to render fluid templates without involving the response, you can use the fetch() method:

<?php
$app->get('/example/{name}', function ($request, $response, $args) {
    $renderedContent = $this->view->fetch('Profile', [
        'name' => $args['name']
    ]);
    // ...
});

Register own view helper namespace

To register a viewhelper namespace in fluid, just add an entry to viewHelperNamespaces configuration: For example:

[
    'abc' => 'Vendor\\Package\\ViewHelper',
]

A hello world view helper looks like this:

<?php
namespace Vendor\Package\ViewHelper;

/**
 *
 * @package Vendor\Package\ViewHelper
 */
class HelloWorldViewHelper extends \TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper
{
    public function render()
    {
        return 'Hello World!';
    }
}

And you call it in fluid template, this way:

<abc:helloWorld />

Fluid Templates

Basically a fluid template may look like this:

<span>Hello {name}!</span>

Fluid ships some basic view helpers, you may use:

<span>
    <f:if condition="{name}">
        <f:then>Hello {name}!</f:then>
        <f:else>Hello stranger!</f:else>
    </f:if>
</span>

There is also an inline notation existing for calling view helpers:

<span>
    Hello {f:if(condition:'{name}', then: '{name}', else: 'Stranger')}!
</span>

A view helper is basically a php class. The fluid default view helpers are prefixed with f:. You may introduce own namespaces for your custom view helpers.

Further fluid documentation

Code is the best documentation. Unfortunately I did not find a full compendium of standalone fluid, because originally this template engine were part of TYPO3 CMS.

However, the fluid package ships some examples. Here you get an overview of how layouts and partials work. The shipped view helper classes can be found here. Each has an usage example in comments.

Also checkout the README of fluid, to understand the concepts and learn how to write own view helpers.

slim-view/fluid 适用场景与选型建议

slim-view/fluid 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 18 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 08 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「framework」 「template」 「view」 「slim」 「typo3」 「fluid」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 slim-view/fluid 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 slim-view/fluid 我们能提供哪些服务?
定制开发 / 二次开发

基于 slim-view/fluid 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 18
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 7
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0
  • 更新时间: 2017-08-20