0

我目前在 Zend 2 的库中工作,其中包括渲染视图脚本。渲染工作正常,我还可以在视图脚本中使用任何其他帮助程序,但是 basePath() 帮助程序抛出异常并显示消息:

No base path provided

我已经尝试在配置中设置 basePath,但它只是在控制器呈现的视图脚本中发生变化。如果它是相关的,这里是呈现视图的代码:

// file: /vendor/mate/library/mate/Group/Functions/GetHtml.php
// $templateDir is either directing to /module/Application/view/group/<name>.phtml
// or to /vendor/mate/library/mate/view/group/<name>.phtml

    $map = new Resolver\TemplateMapResolver(array(
        'group/'.$type => $templateDir,
    ));
    $stack = new Resolver\TemplatePathStack(array(
        'script_paths' => array(
            $viewDir,
        )
    ));

    $resolver->attach($map)    // this will be consulted first
             ->attach($stack);

    $groupModel = new ViewModel(array(
        'elements' => $this->getGroup()->toArray(),
        'groupElement' => $groupElement,
    ));
    $groupModel->setTemplate('group/'.$type);
    $groupHtml = $renderer->render($groupModel);

有谁知道如何让 basePath 在我的视图脚本中工作?

4

2 回答 2

1

必须明确设置助手的基本路径。从渲染器中获取插件并在渲染之前先设置基本路径:

// create your view model

$renderer->plugin('basePath')->setBasePath('/foo');

// render view model now
于 2013-09-08T19:27:29.273 回答
0

问题的出现只是因为您正在创建一个新的、单独的 PhpRenderer 实例,而不是使用已经存在的实例。

如果您通过服务管理器获取渲染器而不是创建新的渲染器,则不需要任何此配置。

于 2013-09-09T09:50:38.630 回答