苗条框架中的Container-> get('route')方法

时间:2018-07-04 04:00:10

标签: php twig slim

Container-> get('route')方法返回什么以及为什么 它用于细长的树枝延伸

1 个答案:

答案 0 :(得分:0)

Slim Twig扩展名需要router(不是路由)实例用于path_for()base_url()之类的自定义模板函数。

示例:

// Register Twig View helper
$container['view'] = function ($c) {
    $view = new \Slim\Views\Twig('path/to/templates', [
        'cache' => 'path/to/cache'
    ]);

    // Instantiate and add Slim specific extension
    $router = $c->get('router');
    $uri = \Slim\Http\Uri::createFromEnvironment(new \Slim\Http\Environment($_SERVER));
    $view->addExtension(new \Slim\Views\TwigExtension($router, $uri));

    return $view;
};

请阅读slimphp/Twig-View documentation