Slim - 在包含的文件中使用路径的变量

时间:2018-04-18 00:06:46

标签: php templates routes slim slim-3

我使用Slim 3构建应用程序。

在某个路线中,我通过object[] test = new object[] { "one", "two", 3, 4 }; NpgsqlCommand cmd = new NpgsqlCommand( "select cardinality(regexp_split_to_array(:COMBINED, E'\t'))", Connection); cmd.Parameters.AddWithValue("COMBINED", string.Join("\t", test)); int results = (int)cmd.ExecuteScalar(); 包含模板的标题( slim / php-view 2.2 ),并且我发送给模板的一些变量是我需要在标题中使用。

有办法吗?

我的路线:

include_once

目标模板($app->get('/', function ( $request, $response) { // some code here... $somedata = ' this is just a test'; return $this->renderer->render($response, "/home.phtml",[ 'somedata' => $somedata, ]); }) ):

home.phtml

1 个答案:

答案 0 :(得分:1)

我的坏。阅读the docs我发现我可以使用模板变量实现我想要的目标,如下所示:

我的路线:

$templateVariables = [
    "title" => "Title"
];
$phpView = new PhpRenderer("./path/to/templates", $templateVariables);

我收录的文件(myheader.php):

<?php echo $title ?>