【发布时间】:2015-06-29 10:02:12
【问题描述】:
我需要将员工 id 和服务 id 插入新表 addservice。我在控制器页面中编写了一个函数 add,我从会话中获取员工 id,从 uri 中的服务表中获取服务 id。 在控制器中
public function add()
{
$this->load->library('session');
$id = $this->uri->segment(4);
$data_to_store = array('employee_id'=>$taxdetails['total'],
'service_id'=>$id);
$this->selected_model->store_employee($data_to_store);
$data['main_content'] = 'admin/selected/list';
$this->load->view('includes/template', $data);
}
在模型中: 这是我的模型文件,其中编写了插入员工 ID 和服务 ID 的代码。
public function store_employee($data)
{
$insert = $this->db->insert('addservice', $data);
return $insert;
}
在查看页面中
<div class="container top">
<ul class="breadcrumb">
<li>
<a href="http://localhost/elfanto/elfanto_billing/admin/addservice">
Admin </a>
<span class="divider">/</span>
</li>
<li class="active">
Service </li>
</ul>
<div class="row">
<div class="span12 columns">
<div >
<?php
$attributes = array('class' => 'form-inline reset-margin', 'id' => 'myform');
$options_manufacture = array(0 => "all");
foreach ($category as $row)
{
$options_manufacture[$row['id']] = $row['name'];
}
//save the columns names in a array that we will use as filter
$options_products = array();
foreach ($service as $array) {
foreach ($array as $key => $value) {
$options_products[$key] = $key;
}
break;
}
?>
</div>
<table class="table table-striped table-bordered table-condensed">
<thead>
<tr>
<th class="header">Service id</th>
<th class="yellow header headerSortDown">Service name </th>
<th class="green header">Service catogary</th>
<th class="red header">Service tax</th>
<th class="red header">Service length</th>
<th class="red header">Service price</th>
<th class="red header">Actions</th>
</tr>
</thead>
<tbody>
<?php
foreach($service as $row)
{
echo '<tr>';
echo '<td>'.$row['id'].'</td>';
echo '<td>'.$row['service_name'].'</td>';
echo '<td>'.$row['category'].'</td>';
echo '<td>'.$row['service_tax'].'</td>';
echo '<td>'.$row['service_length'].'</td>';
echo '<td>'.$row['service_price'].'</td>';
echo '<td class="crud-actions">
<a href="'.site_url("admin").'/selected/add/'.$row['id'].'" class="btn btn-info">Add service</a>
</td>';
echo '</tr>';
}
?>
</tbody>
</table>
<a href='admin/employee/add' class="btn btn-info">Continue as chair renter</a>
<?php echo '<div class="pagination">'.$this->pagination->create_links().'</div>'; ?>
</div>
</div>
此代码不起作用。我无法解决我的问题,谁能更正我的代码。
【问题讨论】:
-
不起作用是什么意思?
-
我没有收到任何错误我得到一个白页
-
在您的控制器中,
$taxdetails是什么? -
这是一个会话变量,我在另一个控制器 employee_controller 中拥有
-
所以当你点击“添加服务”按钮时,你只是得到一个白屏,没有插入数据?
标签: php mysql codeigniter