2014-12-30 19 views
2

我們正在使用Zend框架。我們從管理面板或在運行時創建模塊,但其佈局不工作,因爲我們需要在的application.ini我可以在運行時在Zend框架中的application.ini中添加布局配置

pizzahut.resources.layout.layout = "layout" 
pizzahut.resources.layout.layoutPath = APPLICATION_PATH "/modules/pizzahut/layouts/scripts/" 

定義下面的代碼這是可能的,我們可以運行過程中編輯我們的application.ini使用PHP, 或者我們可以使用PHP在application.ini中添加新的佈局配置?

回答

3

做了一些Google搜索後,我發現我們可以用PHP編輯我們的application.ini

下面是代碼:

$config = parse_ini_file(
    APPLICATION_PATH . "/configs/application.ini", 
    TRUE, 
    INI_SCANNER_RAW 
); 

$config["production"]["$store.resources.layout.layout"] = "layout"; 

$layoutPath = 'APPLICATION_PATH "/modules/' . $store . '/layouts/scripts/"'; 
$config["production"]["$store.resources.layout.layoutPath"] = $layoutPath; 

$result = Helper_common::write_ini_file(
    $config, 
    APPLICATION_PATH . "/configs/application.ini", 
    TRUE 
); 

這裏parse_ini_file用於檢索從application.ini文件與常量內容。

write_ini_file是我打電話重寫application.ini文件的功能。

這裏是write_ini_file功能:

public static function write_ini_file($assoc_arr, $path, $has_sections=FALSE) { 
    $content = ""; 
    if ($has_sections) { 
     foreach ($assoc_arr as $key=>$elem) { 
      $content .= "[".$key."]\n"; 
      foreach ($elem as $key2=>$elem2) { 
       if(is_array($elem2)) 
       { 
        for($i=0;$i<count($elem2);$i++) 
        { 
         $content .= $key2."[] = ".$elem2[$i]."\n"; 
        } 
       } 
       else if($elem2=="") $content .= $key2." = \n"; 
       else $content .= $key2." = ".$elem2."\n"; 
      } 
     } 
    } 
    else { 
     foreach ($assoc_arr as $key=>$elem) { 
      if(is_array($elem)) 
      { 
       for($i=0;$i<count($elem);$i++) 
       { 
        $content .= $key2."[] = ".$elem[$i]."\n"; 
       } 
      } 
      else if($elem=="") $content .= $key2." = \n"; 
      else $content .= $key2." = ".$elem."\n"; 
     } 
    } 

    if (!$handle = fopen($path, 'w')) { 
     return false; 
    } 
    if (!fwrite($handle, $content)) { 
     return false; 
    } 
    fclose($handle); 
    return true; 
}