-
Notifications
You must be signed in to change notification settings - Fork 7.6k
CRUD Buster
Derek Jones edited this page Jul 5, 2012
·
7 revisions
Category:Library | Category:Library::Community | Category:Library::CodeGenerators This will generate CRUD code and output to one single page. All you need to do is copy/paste the code blocks in each appropriate file and you're set!
libraries/CRUD_Buster.php
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/*****
* Code_Generator quickly creates CRUD forms
* @author KMScreative
* @email [email protected]
* @filename CRUD_Buster.php
* @title CRUD_Buster
* @url http://www.kmscreative.com/
* @version 1.0
*****/
class CRUD_Buster {
var $CI;
function __construct()
{
$this->CI =& get_instance();
}
function output_controller_code()
{
$this->CI->data['field_list'] = $this->CI->input->xss_clean($_POST['field_list']);
$this->CI->data['description_list'] = $this->CI->input->xss_clean($_POST['description_list']);
$data_type = strtolower($this->CI->input->xss_clean($_POST['data_type']));
$field_type = strtolower($this->CI->input->xss_clean($_POST['field_type']));
$database_table = $this->CI->input->xss_clean($_POST['database_table']);
$dbfield_type = strtolower($this->CI->input->xss_clean($_POST['dbfield_type']));
$controller_name = ucfirst($data_type); // Ex: Post
if ($controller_name[strlen($controller_name)-1] == "y")
{
$controller_name_mod = $controller_name;
$controller_name_mod[strlen($controller_name_mod)-1] = "i";
$pl_controller_name = $controller_name_mod."es"; // Ex: Companies
}
else
{
$pl_controller_name = $controller_name."s"; // Ex: Posts
}
$model_name = $controller_name."_model"; // Ex: Post_model
$lc_controller_name = strtolower($controller_name); // Ex: post
$field_type_id = $lc_controller_name."_id"; // Ex: post_id
$controller_file_name = "controllers/".$data_type.".php"; // Ex: controllers/post.php
$model_file_name = "models/".$data_type."_model.php"; // Ex: models/post_model.php
$view_add_base = $data_type."/".$data_type; // Ex: post/post
$view_all_file_name = "views/".$view_add_base."_view_all.php"; // Ex: views/view_view_all.php
$view_add_file_name = "views/".$view_add_base."_add_".$data_type.".php"; // Ex: views/view_add_view.php
$view_edit_file_name = "views/".$view_add_base."_edit_".$data_type.".php"; // Ex: views/view_edit_view.php
$view_delete_file_name = "views/".$view_add_base."_delete_".$data_type.".php"; // Ex: views/view_delete.php
$view_delete_base = "delete".$lc_controller_name."_confirmed"; // Ex: deletepost_confirmed
$add_to_model = "\$this->".$controller_name."_model->add".$controller_name."();"; // Ex: $this->Post_model->addPost();
$edit_to_model = "\$this->".$controller_name."_model->edit".$controller_name."();"; // Ex: $this->Post_model->editPost();
$add_to_view = "\$this->template->load('mainTemplate', '".$view_add_base."_add_".$data_type."', \$data);"; // Ex: $this->template->load('mainTemplate', 'post/post_add_post', $data);
$add_to_view_success = "\$this->template->load('mainTemplate', 'common/blank', \$data);"; // Ex: $this->template->load('mainTemplate', 'common/blank', $data);
$edit_to_view = "\$this->template->load('mainTemplate', '".$view_add_base."_edit_".$data_type."', \$data);"; // Ex: $this->template->load('mainTemplate', 'post/post_add_post', $data);
$fieldName_array = explode("|",$this->CI->data['field_list']);
$fieldDesc_array = explode("|",$this->CI->data['description_list']);
$fieldType_array = explode("|",$field_type);
$dbfieldType_array = explode("|",$dbfield_type);
$code = <<<EOD
<table>
<form>
<strong>MySQL:</strong><br /><br />
<textarea name="code" rows="10" cols="100" id="myCpWindow9" class="codepress sql linenumbers-on">
USE database_name;
CREATE TABLE table_name
(
EOD;
$i = 1;
foreach ($dbfieldType_array as $df)
{
if ($i < count($dbfieldType_array))
{
$code .= " ".$df.",\n";
}
elseif ($i = count($dbfieldType_array))
{
$code .= " ".$df."\n";
}
$i++;
}
$code .= <<<EOD
);
</textarea>
<br /><br />
<strong>Controller:</strong> $controller_file_name<br /><br />
<textarea name="code" rows="25" cols="100" id="myCpWindow1" class="codepress php linenumbers-on">
<?php
class $controller_name extends Controller {
function $controller_name()
{
parent::Controller();
\$this->load->library('session');
//\$this->output->enable_profiler(TRUE);
}\n
function view()
{
if ( !\$this->session->userdata('logged_in') )
{
redirect('user/login/', 'location');
}
else
{
if ( \$this->uri->segment(3) == NULL )
{
redirect('$lc_controller_name/view/all/', 'location');
}
if ( \$this->uri->segment(3) == "all" )
{
\$this->load->library('pagination');
\$config['base_url'] = base_url() . '{$lc_controller_name}/view/all/';
\$config['total_rows'] = \$this->db->count_all('$database_table');
\$config['uri_segment'] = '4';
\$config['per_page'] = '10';
\$config['num_links'] = '4';
\$config['full_tag_open'] = '<ul id="dbresultsnav" class="clearfix">';
\$config['full_tag_close'] = '</ul>';
\$config['cur_tag_open'] = '<li id="dbresultsnav"><a id="dbresultsnav">';
\$config['cur_tag_close'] = '</a></li>';
\$config['main_link_open'] = '<li id="dbresultsnav">';
\$config['main_link_close'] = '</li>';
\$config['main_link_class'] = 'id="dbresultsnav"';
\$config['main_curlink_open'] = '<li id="dbresultsnavcur">';
\$config['main_curlink_close'] = '</li>';
\$config['main_curlink_class'] = 'id="dbresultsnavcur"';
\$this->pagination->initialize(\$config);
\$num = \$config['per_page'];
if (\$this->uri->segment(4) != NULL)
{
\$offset = \$this->uri->segment(4);
}
else
{
\$offset = 0;
}
\$data['pagination'] = \$this->pagination->create_links();
\$this->load->model('$model_name', '', TRUE);
\$data['All$pl_controller_name'] = \$this->{$model_name}->findAll{$pl_controller_name}(\$num,\$offset);
\$data['head_title'] = 'My Site - View All $pl_controller_name';
\$this->template->load('mainTemplate', '$lc_controller_name/{$lc_controller_name}_view_all', \$data);
}
else
{
redirect('user/profile/', 'location');
}
}
}
function add()
{
if ( !\$this->session->userdata('logged_in') )
{
redirect('user/login/', 'location');
}
else
{
\$rules = array(\n
EOD;
$i = 1;
foreach ($fieldName_array as $f)
{
if ($i < count($fieldName_array))
{
if ($f == "email")
{
$code .= " '".$f."' => \"trim|valid_email|xss_clean\",\n";
}
else
{
$code .= " '".$f."' => \"trim|xss_clean\",\n";
}
}
elseif ($i = count($fieldName_array))
{
$code .= " '".$f."' => \"trim|xss_clean\"\n";
}
$i++;
}
$code .= <<<EOD
);
\$fields = array(\n
EOD;
$i = 1;
foreach ($fieldDesc_array as $d)
{
if ($i < count($fieldDesc_array))
{
$code .= " '".$fieldName_array[$i-1]."' => \"".$d."\",\n";
}
elseif ($i = count($fieldDesc_array))
{
$code .= " '".$fieldName_array[$i-1]."' => \"".$d."\"\n";
}
$i++;
}
$code .= <<<EOD
);\n
\$this->validation->set_rules(\$rules);
\$this->validation->set_fields(\$fields);
\$this->validation->set_error_delimiters('<div class="error">', '</div>');\n
if (\$this->input->post('submit'))
{
if (\$this->validation->run() == FALSE)
{
\$data['head_title'] = 'My Site - Add $controller_name';
$add_to_view
}
else
{
\$this->load->model('$model_name', '', TRUE);
\$data['query'] = $add_to_model
$add_to_view_success
}
}
else
{
\$data['head_title'] = 'My Site - Add $controller_name';
$add_to_view
}
}
}
function edit()
{
if ( !\$this->session->userdata('logged_in') )
{
redirect('user/login/', 'location');
}
else
{
\$rules = array(\n
EOD;
$i = 1;
foreach ($fieldName_array as $f)
{
if ($i < count($fieldName_array))
{
if ($f == "email")
{
$code .= " '".$f."' => \"trim|valid_email|xss_clean\",\n";
}
else
{
$code .= " '".$f."' => \"trim|xss_clean\",\n";
}
}
elseif ($i = count($fieldName_array))
{
$code .= " '".$f."' => \"trim|xss_clean\"\n";
}
$i++;
}
$code .= <<<EOD
);
\$fields = array(\n
EOD;
$i = 1;
foreach ($fieldDesc_array as $d)
{
if ($i < count($fieldDesc_array))
{
$code .= " '".$fieldName_array[$i-1]."' => \"".$d."\",\n";
}
elseif ($i = count($fieldDesc_array))
{
$code .= " '".$fieldName_array[$i-1]."' => \"".$d."\"\n";
}
$i++;
}
$code .= <<<EOD
);\n
\$this->validation->set_rules(\$rules);
\$this->validation->set_fields(\$fields);
\$this->validation->set_error_delimiters('<div class="error">', '</div>');\n
if (\$this->input->post('submit'))
{
if (\$this->validation->run() == FALSE)
{
\$data['head_title'] = 'My Site - Edit $controller_name';
$edit_to_view
}
else
{
\$this->load->model('$model_name', '', TRUE);
\$data['query'] = $edit_to_model
$add_to_view_success
}
}
else
{
\$data['head_title'] = 'My Site - Edit $controller_name';
$edit_to_view
}
}
}
}
?>
</textarea>
<br /><br />
<strong>Model:</strong> $model_file_name<br /><br />
<textarea name="code" rows="25" cols="100" id="myCpWindow2" class="codepress php linenumbers-on">
<?php
class $model_name extends Model {
function $model_name()
{
parent::Model();
}
function add$controller_name()
{\n
EOD;
$i = 1;
foreach ($fieldType_array as $t)
{
$fn = $fieldName_array[$i-1];
$fd = $fieldDesc_array[$i-1];
$code .= <<<EOD
\$this->data['$fn'] = \$this->input->xss_clean(\$_POST['$fn']);\n
EOD;
$i++;
}
$code .= <<<EOD
\n \$this->db->insert('$database_table', \$this->data);
}\n
function edit$controller_name()
{\n
\$this->data['$field_type_id'] = \$this->input->xss_clean(\$_POST['$field_type_id']);\n
EOD;
$i = 1;
foreach ($fieldType_array as $t)
{
$fn = $fieldName_array[$i-1];
$fd = $fieldDesc_array[$i-1];
$code .= <<<EOD
\$this->data['$fn'] = \$this->input->xss_clean(\$_POST['$fn']);\n
EOD;
$i++;
}
$code .= <<<EOD
\n \$this->db->insert('$database_table', \$this->data, array('$field_type_id' => \$this->data['$field_type_id']));
}\n
EOD;
$code .= <<<EOD
\n function delete$controller_name($$field_type_id)
{
\$this->db->delete('$database_table', array('$field_type_id' => $$field_type_id));
\$messagedata = array(
'msg_text' => '$controller_name deleted successfully.',
'msg_col' => 'MsgBkgGrn'
);
\$this->session->set_userdata(\$messagedata);
}
\n function findAll$pl_controller_name(\$limit = NULL, \$offset = NULL)
{
\$this->db->select('*');
\$this->db->from('$database_table');
\$this->db->orderby("$field_type_id DESC");
\$this->db->limit(\$limit, \$offset);
\$query = \$this->db->get();
return \$query;
}
function displayThis$controller_name()
{
\$this->db->select('*');
\$this->db->from('$database_table');
\$this->db->where('job_id', \$this->uri->segment(3));
\$this->db->limit(1);
\$query = \$this->db->get();
return \$query;
}
\n function findThis$controller_name($$field_type_id)
{
\$this->db->select('*');
\$this->db->where('$field_type_id', \$this->uri->segment(3));
\$this->db->limit(1);
\$query = \$this->db->get('$database_table');
return \$query;
}
}
?>
</textarea>
<br /><br />
<strong>View:</strong> $view_all_file_name<br /><br />
<textarea name="code" rows="25" cols="100" id="myCpWindow10" class="codepress php linenumbers-on">
<h1>View $pl_controller_name</h1><br /><br />
<?php
\$color1 = "odd";
\$color2 = "even";
\$row_count = 0;
?>
<table>
<tr>\n
EOD;
$i = 1;
foreach ($fieldDesc_array as $d)
{
if ($i <= count($fieldDesc_array))
{
$code .= " <th>".$d."</th>\n";
}
$i++;
}
$code .= <<<EOD
</tr>
<?php foreach(\$All{$pl_controller_name}->result() as \$rowAll{$pl_controller_name}): ?>
<?php \$row_color = (\$row_count % 2) ? \$color1 : \$color2; ?>
<tr>
<td class="<?php echo \$row_color; ?>"><?php echo anchor('{$lc_controller_name}/view/'.\$rowAll{$pl_controller_name}->{$lc_controller_name}_id, \$rowAll{$pl_controller_name}->{$lc_controller_name}, array('class' => 'dbplink')); ?> </td>
EOD;
$i = 1;
foreach ($fieldName_array as $f)
{
if ($i <= count($fieldName_array))
{
$code .= " <td class=\"<?php echo \$row_color; ?>\"><?php echo \$rowAll{$pl_controller_name}->".$f."; ?> </td>\n";
}
$i++;
}
$code .= <<<EOD
</tr>
<?php \$row_count++; ?>
<?php endforeach; ?>
</table>
<br />
<?php echo \$pagination; ?><br />
<a class="dbplink" href="<?php echo base_url(); ?>{$lc_controller_name}/add"><img src="<?php echo base_url(); ?>images/icons/add.png" alt="Add a New {$controller_name}" align="middle"></a> <a class="dbplink" href="<?php echo base_url(); ?>{$lc_controller_name}/add">Add a New {$controller_name}</a>
</textarea>
<br /><br />
<strong>View:</strong> $view_add_file_name<br /><br />
<textarea name="code" rows="25" cols="100" id="myCpWindow3" class="codepress php linenumbers-on">
<h1>Add a new $lc_controller_name</h1><br /><br />
<table>
<?php echo form_open('$lc_controller_name/add'); ?>\n\n
EOD;
$i = 1;
foreach ($fieldType_array as $t)
{
$fn = $fieldName_array[$i-1];
$fd = $fieldDesc_array[$i-1];
if ($i <= count($fieldType_array))
{
if ($t == "input")
{
$code .= <<<EOD
<tr>
<td valign="top"><span class="FormFieldTitle">$fd:</span></td>
<td valign="top">
<?php echo \$this->validation->error('$fn'); ?>
<input type="text" name="$fn" value="<?php echo \$this->validation->value('$fn'); ?>" size="50" />
</td>
</tr>\n\n
EOD;
}
elseif ($t == "checkbox")
{
$code .= <<<EOD
<tr>
<td valign="top"><span class="FormFieldTitle">$fd:</span></td>
<td valign="top">
<?php echo \$this->validation->error('$fn'); ?>
<input type="text" name="$fn" value="<?php echo \$this->validation->value('$fn'); ?>" size="50" />
</td>\n
</tr>\n\n
EOD;
}
elseif ($t == "radio")
{
$code .= <<<EOD
<tr>
<td valign="top"><span class="FormFieldTitle">$fd:</span></td>
<td valign="top">
<?php echo \$this->validation->error('$fn'); ?>
<input type="text" name="$fn" value="<?php echo \$this->validation->value('$fn'); ?>" size="50" />
</td>\n
</tr>\n\n
EOD;
}
elseif (($t == "dropdown") && ($fn == "state"))
{
$code .= <<<EOD
<tr>
<td valign="top"><span class="FormFieldTitle">$fd:</span></td>
<td valign="top">
<?php echo \$this->validation->error('$fn'); ?>
<?php
\$choices_states = array('' => 'Select one:', 'AL'=>"Alabama", 'AK'=>"Alaska", 'AZ'=>"Arizona", 'AR'=>"Arkansas",
'CA'=>"California", 'CO'=>"Colorado", 'CT'=>"Connecticut", 'DE'=>"Delaware",
'DC'=>"District Of Columbia", 'FL'=>"Florida", 'GA'=>"Georgia", 'HI'=>"Hawaii",
'ID'=>"Idaho", 'IL'=>"Illinois", 'IN'=>"Indiana", 'IA'=>"Iowa", 'KS'=>"Kansas",
'KY'=>"Kentucky", 'LA'=>"Louisiana", 'ME'=>"Maine", 'MD'=>"Maryland", 'MA'=>"Massachusetts",
'MI'=>"Michigan", 'MN'=>"Minnesota", 'MS'=>"Mississippi", 'MO'=>"Missouri",
'MT'=>"Montana", 'NE'=>"Nebraska", 'NV'=>"Nevada", 'NH'=>"New Hampshire",
'NJ'=>"New Jersey", 'NM'=>"New Mexico", 'NY'=>"New York", 'NC'=>"North Carolina",
'ND'=>"North Dakota", 'OH'=>"Ohio", 'OK'=>"Oklahoma", 'OR'=>"Oregon",
'PA'=>"Pennsylvania", 'RI'=>"Rhode Island", 'SC'=>"South Carolina", 'SD'=>"South Dakota",
'TN'=>"Tennessee", 'TX'=>"Texas", 'UT'=>"Utah", 'VT'=>"Vermont", 'VA'=>"Virginia",
'WA'=>"Washington", 'WV'=>"West Virginia", 'WI'=>"Wisconsin", 'WY'=>"Wyoming");
?>
<?php echo form_dropdown('state', \$choices_states, (\$this->input->post('state')) ? (\$this->input->post('state')) : '\$defaultValue'); ?>
</td>
</tr>\n\n
EOD;
}
elseif (($t == "dropdown") && ($fn != "state"))
{
$code .= <<<EOD
<?php echo \$this->validation->error('$fn'); ?>
<?php
\$choices_{$fn}s = array('' => 'Select one:', 'Choice1'=>"Value1", 'Choice2'=>"Value2");
?>
<?php echo form_dropdown('{$fn}', \$choices_{$fn}s, (\$this->input->post('$fn')) ? (\$this->input->post('$fn')) : '\$defaultValue'); ?>
</td>
</tr>\n\n
EOD;
}
}
$i++;
}
$code .= <<<EOD
<tr>
<td valign="top"> </td>
<td valign="top"><br>
<input name="submit" type="submit" id="submit" value="Submit" style="font-family:Verdana; font-size:8pt; font-weight:bold; color:#FFFFFF; height:20; background:#000066; border:1 solid #808080; cursor:hand">
</td>
</tr>\n
</form>
</table>
</textarea>
<br /><br />
<strong>View:</strong> $view_edit_file_name<br /><br />
<textarea name="code" rows="25" cols="100" id="myCpWindow4" class="codepress php linenumbers-on">
<h1>Edit $lc_controller_name</h1><br /><br />
<table>
<?php echo form_open('$lc_controller_name/edit'); ?>\n
<?php echo form_hidden('$field_type_id', \$this->uri->segment(3)); ?>
<?php echo form_hidden('modified_by', \$this->session->userdata('user_id')); ?>
<?php echo form_hidden('modified_on', date('Y-m-d h:i:s')); ?>\n\n
EOD;
$i = 1;
foreach ($fieldType_array as $t)
{
$fn = $fieldName_array[$i-1];
$fd = $fieldDesc_array[$i-1];
if ($t == "input")
{
$code .= <<<EOD
<tr>
<td valign="top"><span class="FormFieldTitle">$fd:</span></td>
<td valign="top">
<?php echo \$this->validation->error('$fn'); ?>
<input type="text" name="$fn" value="<?php echo (\$this->validation->value('$fn')) ? (\$this->validation->value('$fn')) : (\$row->$fn);?>" size="25" />
</td>
</tr>\n\n
EOD;
}
elseif ($t == "checkbox")
{
$code .= <<<EOD
<tr>
<td valign="top"><span class="FormFieldTitle">$fd:</span></td>
<td valign="top">
<?php echo \$this->validation->error('$fn'); ?>
<input type="text" name="$fn" value="<?php echo \$this->validation->value('$fn'); ?>" size="50" />
</td>\n
</tr>\n\n
EOD;
}
elseif ($t == "radio")
{
$code .= <<<EOD
<tr>
<td valign="top"><span class="FormFieldTitle">$fd:</span></td>
<td valign="top">
<?php echo \$this->validation->error('$fn'); ?>
<input type="text" name="$fn" value="<?php echo \$this->validation->value('$fn'); ?>" size="50" />
</td>\n
</tr>\n\n
EOD;
}
elseif (($t == "dropdown") && ($fn == "state"))
{
$code .= <<<EOD
<tr>
<td valign="top"><span class="FormFieldTitle">$fd:</span></td>
<td valign="top">
<?php
if ((isset($_POST)) AND (!\$this->input->post('state')))
{
echo "One must be selected<br />";
}
?>
<?php
\$choices_states = array('' => 'Select one:', 'AL'=>"Alabama", 'AK'=>"Alaska", 'AZ'=>"Arizona", 'AR'=>"Arkansas",
'CA'=>"California", 'CO'=>"Colorado", 'CT'=>"Connecticut", 'DE'=>"Delaware",
'DC'=>"District Of Columbia", 'FL'=>"Florida", 'GA'=>"Georgia", 'HI'=>"Hawaii",
'ID'=>"Idaho", 'IL'=>"Illinois", 'IN'=>"Indiana", 'IA'=>"Iowa", 'KS'=>"Kansas",
'KY'=>"Kentucky", 'LA'=>"Louisiana", 'ME'=>"Maine", 'MD'=>"Maryland", 'MA'=>"Massachusetts",
'MI'=>"Michigan", 'MN'=>"Minnesota", 'MS'=>"Mississippi", 'MO'=>"Missouri",
'MT'=>"Montana", 'NE'=>"Nebraska", 'NV'=>"Nevada", 'NH'=>"New Hampshire",
'NJ'=>"New Jersey", 'NM'=>"New Mexico", 'NY'=>"New York", 'NC'=>"North Carolina",
'ND'=>"North Dakota", 'OH'=>"Ohio", 'OK'=>"Oklahoma", 'OR'=>"Oregon",
'PA'=>"Pennsylvania", 'RI'=>"Rhode Island", 'SC'=>"South Carolina", 'SD'=>"South Dakota",
'TN'=>"Tennessee", 'TX'=>"Texas", 'UT'=>"Utah", 'VT'=>"Vermont", 'VA'=>"Virginia",
'WA'=>"Washington", 'WV'=>"West Virginia", 'WI'=>"Wisconsin", 'WY'=>"Wyoming");
?>
<?php /* echo form_dropdown('state', \$choices_states, (\$this->input->post('state')) ? (\$this->input->post('state')) : '\$defaultValue'); */ echo form_dropdown('state', \$choices_states, \$row->state); ?>
</td>
</tr>\n\n
EOD;
}
elseif (($t == "dropdown") && ($fn != "state"))
{
$code .= <<<EOD
<?php echo \$this->validation->error('$fn'); ?>
<?php
\$choices_{$fn}s = array('' => 'Select one:', 'Choice1'=>"Value1", 'Choice2'=>"Value2");
?>
<?php echo form_dropdown('{$fn}', \$choices_{$fn}s, (\$this->input->post('$fn')) ? (\$this->input->post('$fn')) : '\$defaultValue'); ?>
</td>
</tr>\n\n
EOD;
}
$i++;
}
$code .= <<<EOD
<tr>
<td valign="top"> </td>
<td valign="top"><br>
<input name="submit" type="submit" id="submit" value="Submit" style="font-family:Verdana; font-size:8pt; font-weight:bold; color:#FFFFFF; height:20; background:#000066; border:1 solid #808080; cursor:hand">
</td>
</tr>
</form>
</table>
</textarea>
<br /><br />
<strong>View:</strong> $view_delete_file_name<br /><br />
<textarea name="code" rows="5" cols="100" id="myCpWindow5" class="codepress php linenumbers-on">
<br />
<?php echo anchor('$lc_controller_name/$view_delete_base/'. \$this->uri->segment(3), 'Yes, remove $lc_controller_name', array('class' => 'dbplink')); ?> | <?php echo anchor('$lc_controller_name/view', 'Cancel', array('class' => 'dbplink')); ?>
</textarea>
</form></table>
<br /><br />
EOD;
return $code;
}
}
?>
application/controllers/crud.php
<?php
class Crud extends MY_Controller {
function __construct()
{
parent::MY_Controller();
$this->load->library('session');
$this->load->library('CRUD_Buster');
//$this->output->enable_profiler(TRUE);
}
function index()
{
if ( !$this->session->userdata('usertype') == "Admin" )
{
redirect('home', 'location');
}
else
{
$rules = array(
'data_type' => "trim|required|xss_clean",
'field_list' => "trim|required|xss_clean",
'description_list' => "trim|required|xss_clean",
'database_table' => "trim|required|xss_clean",
'dbfield_type' => "trim|required|xss_clean",
'field_type' => "trim|required|xss_clean"
);
$fields = array(
'data_type' => "Data Type",
'field_list' => "List of Fields",
'description_list' => "Description List",
'database_table' => "Database Table",
'dbfield_type' => "Database Field Type",
'field_type' => "Field Type"
);
$this->validation->set_rules($rules);
$this->validation->set_fields($fields);
$this->validation->set_error_delimiters('<div class="error">', '</div>');
if ($this->validation->run() == FALSE)
{
$data['head_title'] = 'Create Code';
$this->template->load('mainTemplate', 'crud_buster/code_create', $data);
}
else
{
$data['code'] = $this->crud_buster->output_controller_code();
$data['javascript'] = ('');
$data['head_title'] = 'View Code';
$this->template->load('mainTemplate', 'crud_buster/code_view', $data);
}
}
}
}
?>
views/crud_buster/code_create.php
<h1>Create a form</h1>
<table>
<?php echo form_open('code_generator/index'); ?>
<?php echo form_hidden('added_by', $this->session->userdata('user_id')); ?>
<?php echo form_hidden('added_on', date('Y-m-d h:i:s')); ?>
<tr>
<td valign="top"><span class="FormFieldTitle">Type of data this form will handle<br />(singular -- do not add an "S" at the end!):<br />Example: user</span></td>
<td valign="top">
<?php echo $this->validation->error('data_type'); ?>
<input type="text" name="data_type" value="<?php echo $this->validation->value('data_type'); ?>" size="25" />
</td>
</tr>
<tr>
<td valign="top"><span class="FormFieldTitle">Field List (separate by |):<br />Example: first_name|last_name|address1</span></td>
<td valign="top">
<?php echo $this->validation->error('field_list'); ?>
<textarea name="field_list" rows="4" cols="70"><?php echo $this->validation->value('field_list'); ?></textarea>
</td>
</tr>
<tr>
<td valign="top"><span class="FormFieldTitle">Field Descriptions (separate by |):<br />Example: First Name|Last Name|Street Address</span></td>
<td valign="top">
<?php echo $this->validation->error('description_list'); ?>
<textarea name="description_list" rows="4" cols="70"><?php echo $this->validation->value('description_list'); ?></textarea>
</td>
</tr>
<tr>
<td valign="top"><span class="FormFieldTitle">Database Table:</span></td>
<td valign="top">
<?php echo $this->validation->error('database_table'); ?>
<textarea name="database_table" rows="4" cols="70"><?php echo $this->validation->value('database_table'); ?></textarea>
</td>
</tr>
<tr>
<td valign="top"><span class="FormFieldTitle">Database Field Types (separate by |):<br />Example: first_name VARCHAR(200) NULL PRIMARY KEY auto_increment|last_name VARCHAR(150) NULL|address1 VARCHAR (150) NULL</span></td>
<td valign="top">
<?php echo $this->validation->error('dbfield_type'); ?>
<textarea name="dbfield_type" rows="4" cols="70"><?php echo $this->validation->value('dbfield_type'); ?></textarea>
</td>
</tr>
<tr>
<td valign="top"><span class="FormFieldTitle">Form Field Types (separate by |):<br />Valid types: input|textarea|dropdown|checkbox|radio</span></td>
<td valign="top">
<?php echo $this->validation->error('field_type'); ?>
<textarea name="field_type" rows="4" cols="70"><?php echo $this->validation->value('field_type'); ?></textarea>
</td>
</tr>
<tr>
<td valign="top"> </td>
<td valign="top"><br>
<input name="submit" type="submit" id="submit" value="Create Code" style="font-family:Verdana; font-size:8pt; font-weight:bold; color:#FFFFFF; height:20; background:#000066;
border:1 solid #808080; cursor:hand">
</td>
</tr>
</form>
</table>
views/crud_buster/code_view.php
<?php echo $code; ?>