Skip to content

Instantly share code, notes, and snippets.

@gelinger777
Created June 25, 2015 11:49
Show Gist options
  • Save gelinger777/7062d90c597d4f959bc1 to your computer and use it in GitHub Desktop.
Save gelinger777/7062d90c597d4f959bc1 to your computer and use it in GitHub Desktop.
Generate Crud Code for all tables in Codeigniter with Grocery Crud
function simple_crud($table_name) {
$this->load->helper('inflector');
$this->load->helper('string');
$tables = $this->db->list_tables();
foreach ($tables as $table) {
$table = str_replace("a3m_", '', $table);
$table = str_replace("qh_", '', $table);
$table = str_replace("ref_", '', $table);
echo '<li><a href="/{$lang->lang()}/stpanel/ControlPanel/control_' . $table . '"> <i class="fa fa-book"></i> <span>' . humanize($table) . '</span></a></li>' . "\n";
}
foreach ($tables as $table) {
$table_name_orig = $table;
$table = str_replace("a3m_", '', $table);
$table = str_replace("qh_", '', $table);
$table = str_replace("ref_", '', $table);
echo " \n "
. "function control_" . $table . "(){ \n"
. ' $crud = new grocery_CRUD();
$crud->set_table(\'' . $table_name_orig . '\' );
';
$fields = $this->db->list_fields($table_name_orig);
$i = 0;
$cols = "";
$cols2 = "";
foreach ($fields as $field) {
if ($i > 0) {
$cols = $cols . " '" . $field . '\',';
$cols2 = $cols2 . '$crud->display_as(\'' . $field . '\',\'' . humanize($field) . '\');' . " \n";
}
$i++;
}
echo ' $crud->columns(' . reduce_multiples($cols, ',', true) . ');
' . $cols2 . '
//$crud->set_relation(\'company_id\',\'qh_company\',\'company_name\');
$output = $crud->render();
$data[\'admin_content\']=$this->_example_output($output);
$this->smarty->view(\'stpanel/main.tpl\', $data);'
. "}"
;
}
die();
$crud = new grocery_CRUD();
$crud->set_table($table_name);
//$crud->columns('job_title','date_added');
$crud->display_as('salesRepEmployeeNumber', 'company_id', 'from Employeer')
->display_as('company_id', 'Company')
->display_as('contactLastName', 'Last Name');
$crud->set_subject('Job');
//$crud->set_relation('company_id','qh_company','company_name');
$output = $crud->render();
$data['admin_content'] = $this->_example_output($output);
$this->smarty->view('stpanel/main.tpl', $data);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment