2012-12-14 28 views
0

我在文檔中發現,有可能有下面的代碼:如何使用配置陣列文件適配器?

// config.php 
$settings = array(); 

// index.php 
require_once('config.php'); 
$config = new \Phalcon\Config($settings); 

但是,它可以創建配置不陣列,但包含數組名? 我指的是以下幾點:

// config.php 
return array(....); 

// index.php 
$config = new \Phalcon\Config\Array('config.php'); 

或者水木清華這樣嗎?

回答

1

此刻這是不可行的。但是,您可以輕鬆地擴展爾康\ CONFIG \陣列如下:

class MyConfig extends \Phalcon\Config 
{ 
    public function __construct($file) 
    { 
     if (!file_exists($file)) 
     { 
      throw new \Phalcon\Config\Exception(
       'File was not found' 
      ); 
     } 

     $data = require($file); 

     if (!is_array($data)) 
     { 
      throw new \Phalcon\Config\Exception(
       'File supplied does not contain an array' 
      ); 
     } 

     parent::__construct($data); 
    } 
} 

上面應該給你什麼,你需要