Php Zend框架配置文件JSON
目前我正在学习ZF2。在浏览“Getting start”时,我看到模块的每个配置文件都充满了PHP数组。文档中的一个示例:Php Zend框架配置文件JSON,php,json,zend-framework2,Php,Json,Zend Framework2,目前我正在学习ZF2。在浏览“Getting start”时,我看到模块的每个配置文件都充满了PHP数组。文档中的一个示例: <?php return array( 'controllers' => array( 'invokables' => array( 'Album\Controller\Album' => 'Album\Controller\AlbumController', ), ),
<?php
return array(
'controllers' => array(
'invokables' => array(
'Album\Controller\Album' => 'Album\Controller\AlbumController',
),
),
// The following section is new and should be added to your file
'router' => array(
'routes' => array(
'album' => array(
'type' => 'segment',
'options' => array(
'route' => '/album[/:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'Album\Controller\Album',
'action' => 'index',
),
),
),
),
),
'view_manager' => array(
'template_path_stack' => array(
'album' => __DIR__ . '/../view',
),
),
);
我会尝试修改Module.php
文件中的getConfig()
函数:
return \Zend\Config\Factory::fromFile(__DIR__ . '/config/module.config.json', false);
我建议不要使用JSON。过一段时间,您会希望在配置文件中为ServiceManager创建一个单行工厂,然后在php中需要它。如果所有数组(
)都让您恼火并使其看起来很难看,那么请使用PHP5.4的[]
数组语法。