jibundeyare/silex-php-view

为silex框架提供的最小化php视图服务提供商

1.2.0 2019-11-20 14:29 UTC

This package is not auto-updated.

Last update: 2024-09-19 13:12:28 UTC


README

为silex框架提供的最小化php视图服务

安装

打开终端,进入您的项目目录,然后输入

composer require jibundeyare/silex-php-view

参数

view.path : 存放php模板文件的目录的路径。

视图目录

建议创建一个单独的目录来存储视图。

在示例中,我们使用了以下目录结构

project/
  public/
    index.php
  templates/
    hello.php
  vendor/

注册

// public/index.php
$app->register(new SilexPhpView\ViewServiceProvider(), [
    'view.path' => __DIR__.'/../templates',
]);

用法

// public/index.php
$app->get('/test', function() use($app) {
    $greeting = 'Hello!';

    return $app['view']->render('hello.php', [
        'greeting' => $greeting,
    ]);
});

// templates/hello.php
echo $greeting;