2013-02-03 58 views
0

目前我正在學習ZF2。在經歷「Getting started」的過程中,我發現模塊的每個配置文件都充滿了PHP數組。來自文檔的示例:Zend Framework配置文件JSON

<?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', 
     ), 
    ), 
); 

帶數組的數組。其實我知道,該數組只是函數的名稱,更像是帶有鍵/值對的映射。

一個在Zend MODS的指出,我們可以使用JSON用於配置文件: http://framework.zend.com/manual/2.0/en/user-guide/routing-and-controllers.html#comment-696979913

有誰可以爲初學者提供的例子嗎?我真的更喜歡使用JSON格式的文件配置,而不是陣列/地圖,但我無法在ZF主頁上找到它。或者,也許我不應該這樣做?

+0

我建議不要使用JSON。在賽道上的某段時間,您需要在配置文件中爲ServiceManager創建一個單行工廠,然後您需要在php中使用它。 – superdweebie

+0

如果所有''數組(''煩你,並使其看起來很醜,然後使用PHP 5.4的'[]'數組語法。 – superdweebie

回答

0

我會嘗試修改您Module.php文件中的getConfig()功能:

return \Zend\Config\Factory::fromFile(__DIR__ . '/config/module.config.json', false);