Seeing as nobody has actually shown an ini file yet .....
I use parse ini to pick up files in a framework which define how PDO should behave in the model direction, and how the forms should be rendered in the view direction.
staff.model.boot.php
PHP Code:
;<?php exit(' you won\'t see my ini file'); ?>
; Bootstrap file for simple models
; Options for PDO are : INT STR NULL BOOL LOB
; params : PDO - field_type - size - HTML_Label
[attributes]
id = INT
type_ref = INT
name = STR-text-30-Name
title = STR-text-30-Job title
email = STR-text-30-Email
ext = INT-text-30-Ext no:
tel = STR-text-30-Tel
descrip = STR
rank = INT-text-2-Order on page
[second_section]
; left empty
I name them .php rather than .ini so they is a slightly less chance they will be shown as plain text.
Here's a (rather badly named) helper which grabs these ini files:
iniconfig.class.php
PHP Code:
<?php
/**
* class IniConfig
*
* Bootstraps from an .ini file and provides basic crud for that single table
*
**/
class IniConfig {
public $ini_file;
public $config;
function __construct( $model_name="" ){
if( $model_name=="" ) { trigger_error("No ini file requested", E_USER_ERROR);}
$this->ini_file = $model_name. ".model.boot.php" ;
if( !$this->config = parse_ini_file( $model_name . ".model.boot.php", true) ) {
trigger_error("Ini file does not exist : $model_name", E_USER_ERROR);
}
}
// each ini section holds an array we need to tell it what to look for
function setKeyTarget( $key ){
if ( in_array( $key , array_keys($this->config ) ) ) {
return $this->config[$key] ;
}else{
trigger_error( "No such settings $key" , E_USER_ERROR );
}
}
}
?>
Bookmarks