Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用zend framework 3在变量中呈现模板?_Php_Rendering_Zend Framework3_Laminas Api Tools - Fatal编程技术网

Php 如何使用zend framework 3在变量中呈现模板?

Php 如何使用zend framework 3在变量中呈现模板?,php,rendering,zend-framework3,laminas-api-tools,Php,Rendering,Zend Framework3,Laminas Api Tools,我在写API。 试图呈现一些模板, 例如索引 配置: 'index/index' => __DIR__ . '/../view/layout/index.phtml', index.phtml: <span><?= $this->var ?></span> 不要生成它,也不要显示任何错误… 我的方向是对的吗? 我的错误在哪里?view/layout/index.phtml: <?php echo $this->key ?&g

我在写API。 试图呈现一些模板, 例如索引

配置:

'index/index' => __DIR__ . '/../view/layout/index.phtml',
index.phtml:

<span><?= $this->var ?></span>
不要生成它,也不要显示任何错误…
我的方向是对的吗?

我的错误在哪里?

view/layout/index.phtml:

    <?php echo $this->key ?>
    <?php echo $this->value ?>
    <?php echo $this->key ?>
    <?php echo $this->value ?>
    $view = new \Zend\View\Renderer\PhpRenderer();
    $resolver = new \Zend\View\Resolver\TemplateMapResolver();
    $resolver->setMap(array(
        'mailTemplate' => __DIR__ . '/../../../../view/layout/index.phtml'
    ));
    $view->setResolver($resolver);

    $viewModel = new \Zend\View\Model\ViewModel();
    $viewModel->setTemplate('mailTemplate')
        ->setVariables(array(
            'key' => '1111111111111',
            'value' => '2222222222222'
        ));

    $result = $view->render($viewModel);
    echo $result;