2

免责声明:我完全是 Zend 的菜鸟。

我正在评估Zend Framework 2,并尝试将其配置为与ZfTwig一起使用以进行模板化。(见这里:https ://github.com/mtymek/ZfTwig )

我通过Step 3配置确定,但我无法弄清楚Step 4

我尝试将以下内容放入application.config,但没有好处。

我应该把这个放在哪里?

return array(
    'di' => array(
        'instance' => array(
            // setup other stuff...
            // ...

            // setup view script resolvers - very similar to configuration
            // from ZendSkeletonApplication
            'Zend\View\Resolver\AggregateResolver' => array(
                'injections' => array(
                    'Zend\View\Resolver\TemplateMapResolver',
                    'ZfTwig\TemplatePathStack',
                ),
            ),
            'Zend\View\Resolver\TemplateMapResolver' => array(
                'parameters' => array(
                    'map'  => array(
                        'layout/layout' => __DIR__ . '/../view/layout/layout.twig',
                    ),
                ),
            ),
            'ZfTwig\TemplatePathStack' => array(
                'parameters' => array(
                    'paths'  => array(
                        'application' => __DIR__ . '/../view',
                    ),
                ),
            ),
            // Tell TwigRenderer how it should locate .twig files
            'ZfTwig\TwigRenderer' => array(
                'parameters' => array(
                    'resolver' => 'Zend\View\Resolver\AggregateResolver',
                ),
            ),
        ),
    );

谷歌没有帮助......我在 Zend 的网站或任何地方都找不到任何文档告诉我应该去哪里。

谢谢您的帮助!

4

1 回答 1

6

di配置来自 Zend Framework 2 的第一个 beta版本。Zend\Di组件仍然可用,但在内部(与许多其他模块一样)由Zend\ServiceManager.

基本上,两者都能够提供依赖注入。只有Zend\Di它可以自动执行这种操作,并且Zend\ServiceManager还有其他选项可以使依赖注入更加明确。

To give an answer to your question: ZfcTwig is now part of ZF-Commons and https://github.com/ZF-Commons/ZfcTwig is the location you have to search for now. Just for your insights, this file is an example of a factory used by the service manager. For more background of service managers in Zend Framework 2, I have written a blog post two months ago which might be interesting.

于 2012-12-07T22:18:10.833 回答