monkeycode/staticpageprovider

v1.0 2014-02-20 16:18 UTC

This package is auto-updated.

Last update: 2024-09-28 22:57:07 UTC


README

Silex ControllerProvider,帮助减少使用Silex和Twig构建小型网站时静态页面配置的样板代码。

Build Status

用法

$controllers = new StaticPageControllerProvider(
    [
        'home'     => ['path' => '/',           'template' => 'index.html.twig'],
        'about'    => ['path' => '/about',      'template' => 'team.html.twig'],
        'services' => ['path' => '/services',   'template' => 'services.html.twig'],
        'contact'  => ['path' => '/getintouch', 'template' => 'contact.html.twig']
    ]
);

缓存头

Symfony的Response::setCache()方法接受的选项可以作为第二个参数进行配置,并将用于所有注册的页面

$controllers = new StaticPageControllerProvider(
    [
        'home' => ['path' => '/', 'template' => 'index.html.twig']
    ],
    ['s_maxage' => 3600]
);

内容类型

可以使用可选的type参数来设置响应的内容类型

$controllers = new StaticPageControllerProvider([
    'descr' => [
        'path' => '/descr',
        'template' => 'descr.xml.twig',
        'type' => 'text/xml',
    ]
]);