我使用codeigniter.I在视图页面中有一个表单将数据发布到控制器类。我对此没有太多了解。有人可以帮我编码吗? 我的观点页面:
<?php
//form data
$attributes = array('class' => 'form-horizontal', 'id' => '');
$indiatimezone = new DateTimeZone("Asia/Kolkata" );
$date = new DateTime();
$date->setTimezone($indiatimezone);
//form validation
echo validation_errors();
echo form_open('admin/billing/ticket_add', $attributes);
?>
<div id="ticket">
<table style=" border-collapse: collapse;">
<tr>
<th>Employee</th>
<th>Start Time</th>
<th>ID</th>
<th>Mins</th>
</tr>
<tr id="1" ondblclick="myid(this)">
<input type="text" name="id" value="<?php echo $date->format( 'H:i' ); ?>"/>
<td contenteditable="true"><?php echo form_dropdown('employee', $options_category, set_value('employee'),'style="border-radius:0px; height:15px; font-size:10px; width:70px"');?></td>
<td contenteditable="true"><input type="text" name="start_time" value="<?php echo $date->format( 'H:i' ); ?>"/></td>
<td contenteditable="true" ondblclick="mylist()"><input type="text" name="pid" value="<?php echo set_value('pid'); ?>"/></td>
<td contenteditable="true" class="nr"><input type="text" name="mins" value="<?php echo set_value('mins'); ?>"/></td>
</tr>
<tr id="2" ondblclick="myid(this)">
<td contenteditable="true"><?php echo form_dropdown('employee', $options_category, set_value('employee'),'style="border-radius:0px; height:15px; font-size:10px; width:70px"');?></td>
<td contenteditable="true"><input type="text" name="start_time" value="<?php echo $date->format( 'H:i' ); ?>"/></td>
<td contenteditable="true" ondblclick="mylist()"><input type="text" name="pid" value="<?php echo set_value('pid'); ?>"/></td>
<td contenteditable="true" class="nr"><input type="text" name="mins" value="<?php echo set_value('mins'); ?>"/></td>
</tr>
</div>
<?php echo form_close(); ?>
这里我将数据发送到控制器功能ticket_add.Below是我在控制器中的tickect_add函数。
public function ticket_add()
{
if ($this->input->server('REQUEST_METHOD') === 'POST')
{
$this->form_validation->set_rules('employee', 'employee');
$this->form_validation->set_rules('start_time', 'start_time');
$this->form_validation->set_rules('pid', 'pid');
$this->form_validation->set_rules('mins', 'mins');
$this->form_validation->set_error_delimiters('<div class="alert alert-error"><a class="close" data-dismiss="alert">×</a><strong>', '</strong></div>');
//if the form has passed through the validation
if ($this->form_validation->run())
{
$data_to_store = array(
'employee' => $this->input->post('employee'),
'start_time' => $this->input->post('start_time'),
'pid' => $this->input->post('pid'),
'mins' => $this->input->post('mins'),
);
}
}
$this->billing_model->store_bill($data_to_store);
$data['main_content'] = 'admin/billing/ticket_page';
$this->load->view('includes/template', $data);
}
在这里,我获取已发布的值并将其发送到模型文件以存储我的数据。怎么做。有人可以帮助我吗?
答案 0 :(得分:0)
$this->billing_model->store_bill($data_to_store);
此行将$ data_to_store传递给billing_model
中的函数store_bill答案 1 :(得分:0)
您应该在模型中进行调试以检查问题...
将此视为billing_model
public function store_bill($data_to_store)
{
$this -> db -> insert( 'your_table_name', $data_to_store );
// try this
echo $this->db->last_query();
// you will get complete insert query from above line...
// Execute it in phpmyadmin to check for any error..
}