Hi all this is what my brain came up with I don’t know if it’s logical or not that is why I am posting it here.
I did not want to mess around with yaml cause I don’t have pear library’s installed on my machine to make it work since its not native on php 5 yet, so I thought of the next easiest thing INI files
for each table in your db you would create an ini file the name must match the name of a table in a db and the result array much match the array the $this->dbforge->add_fields().
main controller
<?php
class Blog extends Controller {
function Blog()
{
parent::Controller();
$this->load->model('Blog');
$this->load->library('db_utils');
}
function index()
{
$this->load->view('welcome_message');
}
function set_up_db(){
$table_names=$this->db_utils->get_tables();
$this->Blog->make_tables($table_names);
}
}
?>
model
<?php
class Blog extends Model {
function Blog() {
parent::Model();
$this->load->library('db_util');
}
// this function takes and array of db tables names you
// want to create. The names of the table corresponds to
// names of ini files created for each table
// array('blog','comments')
// would mean you would need a blog.ini and comments.ini
// that would describe the data type for each field in the table
function make_tables($tables_array) {
$this->db_util($tables_array);
}
}
?>
db util library
<?php if(!defined('BASEPATH')) exit('No Direct access');
class Db_util {
function Db_util()
{
$CI=& get_instance();
$this->load->dbforge();
}
function get_tables(){
// array of files in the ini dir
$files = array();
// path to db ini files
$path=base_url()."/db_ini";
$handle=opendir($path);
chdir($handle);
while ($file !== false) {
$file=readDir($handle);
$files[] = $file;
}
$temp = preg_grep("/ini$/", $files);
$table_names=array();
foreach($temp as $val) {
$x=substr($val,-4,4);
$table_names[]=$x;
}
return $table_names;
}
function make_tables($array){
foreach($array as $value) {
$ini_url=base_path()."/db_ini/$value.ini";
$fields = parse_ini_file($ini_url, true);
$this->dbforge->add_field($fields);
$this->dbforge->create_table($value);
}
}
}
?>
you would have to make an ini file for each table in the database like this and then store them in a db_ini Directory
; database ini
; this is a database schema for that works with the
; codeigniter forge db class
;
;
[blog_id]
type=int
contraint=5
unsigned=true
auto_increment=true
[blog_title]
type=varchar
contraint=100
[blog_author]
type=varchar
constraint=100
defualt=me
[blog_description]
type=text
null=true
I had this revalation in my sleep so I don’t know if it’s logical to make an ini file for each table in a database or not
any way I got a job interview at 10 am and then it’s off to myrtle beach, sc for a vacation I will play around with this there
I hope you can tell me if this approach is logical or not