#!/usr/bin/env php $params, 'flags' => $flags, 'args' => $args); } class Generate { function __construct() { $this->CI = &get_instance(); $this->CI->spyc = new Spyc(); $this->Ci->fixture = new Fixture(); $this->args_arr = args_arr(); $this->params = $this->args_arr['params']; $this->args = $this->args_arr['args']; $this->flags = $this->args_arr['flags']; if (isset($this->args[0])) { $function = $this->args[0]; $this->$function(); } else { echo " Please specify what task to run: e.g.: 'php generate fixtures' or 'php generate migration' flags can by specified by '-flag' parameters by 'PARAM=VALUE' e.g.: 'php generate fixtures -verbose' 'php generate fixtures db=different_db_than_default' To receive more information on a task type 'php generate help task' e.g.: 'php generate help migration' "; } } function fixtures() { $db = isset($this->params['db'])? $this->params['db']:'db'; $prefix = ($db == 'db2')? "db2_":""; /** * Update this controller to your default controller */ $this->CI = set_controller('welcome'); echo "generating...\n"; $this->CI->load->database(); $tables = $this->CI->$db->list_tables(); foreach ($tables as $table) { echo $table; $fields = $this->CI->$db->list_fields($table); $fixt_name= 'fixtures/'.$prefix.$table.'_fixt.yml'; if (file_exists($fixt_name)) { echo "fixture $fixt_name already exits!\n"; } else { $h = fopen($fixt_name, 'w') or die("can't open file"); //write fixture! foreach (array('1', '2', '3') as $rowname) { fwrite($h, $rowname.":\n"); foreach ($fields as $field) { //echo $field; fwrite($h, ' ' . $field . ": \n"); } fwrite($h, "\n"); } echo " *** fixture $fixt_name written.\n"; fclose($h); } } } } $gen = new Generate();