定制 projek-xyz/slim-plates 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

projek-xyz/slim-plates

最新稳定版本:v0.2.2

Composer 安装命令:

composer require projek-xyz/slim-plates

包简介

Render your Slim 3 application views using Plates template engine.

README 文档

README

Version Lisence Actions Status Coveralls Code Climate Maintainability SymfonyInsight Grade

Plates Template Integration for Slim micro framework 3

Render your Slim 3 application views using Plates template engine.

Install

Via Composer

$ composer require projek-xyz/slim-plates --prefer-dist

Requires Slim micro framework 3 and PHP 5.5.0 or newer.

Usage

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

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

// Register Plates View helper:
// Option 1, using PlatesProvider
$container->register(new \Projek\Slim\PlatesProvider);

// Option 2, using Closure
$container['view'] = function ($c) {
    $view = new \Projek\Slim\Plates([
        // Path to view directory (default: null)
        'directory' => 'path/to/views',
        // Path to asset directory (default: null)
        'assetPath' => 'path/to/static/assets',
        // Template extension (default: 'php')
        'fileExtension' => 'tpl',
        // Template extension (default: false) see: http://platesphp.com/extensions/asset/
        'timestampInFilename' => false,
    ]);

    // Set \Psr\Http\Message\ResponseInterface object
    // Or you can optionaly pass `$c->get('response')` in `__construct` second parameter
    $view->setResponse($c->get('response'));

    // Instantiate and add Slim specific extension
    $view->loadExtension(new Projek\Slim\PlatesExtension(
        $c->get('router'),
        $c->get('request')->getUri()
    ));

    return $view;
};

// Define named route
$app->get('/hello/{name}', function ($request, $response, $args) {
    return $this->view->render('profile', [
        'name' => $args['name']
    ]);
})->setName('profile');

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

NOTE:

  • If you are using option 1 please make sure you already have $container['settings']['view'] in your configuration file.
  • Plates::setResponse() is required to use Plates::render() otherwise \LogicException will thrown.

Custom functions

This component exposes some Slim functions to your Plates templates.

pathFor()

You can use this function to generate complete URLs to any Slim application named route. Example:

<?php $this->layout('base-template') ?>

<?php $this->start('body') ?>
<h1>Hallo <?=$this->e($name)?></h1>
<small><?=$this->pathFor('profile', ['name'=> $name])?></small>
<?php $this->stop() ?>

baseUrl($permalink = '')

Retrieve the base url of your Slim application. Example:

<a href="<?=$this->baseUrl()?>">Some Link</a>

Or you can pass a permalink

<a href="<?=$this->baseUrl('some/path')?>">Some Other Link</a>

basePath()

Retrieve the base url of your Slim application. Example:

<link rel="stylesheet" href="<?=$this->basePath().'asset/css/main.css'?>">

uriFull()

Retrieve full request URI.

uriScheme()

Retrieve the scheme component of the URI.

uriHost()

Retrieve the host component of the URI

uriPort()

Retrieve the port component of the URI.

uriPath()

Retrieve the path component of the URI.

uriQuery()

Retrieve the query string component of the URI.

uriFragment()

Retrieve the fragment component of the URI.

Contributing

Please see CONTRIBUTING and CONDUCT for details.

License

This library is open-sourced software licensed under MIT license.

统计信息

  • 总下载量: 73.43k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 29
  • 点击次数: 3
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 26
  • Watchers: 4
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 未知

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固