【发布时间】:2015-09-23 02:53:30
【问题描述】:
我正在使用 codeigniter。我有一个视图文件,我在其中选择员工并使用表单操作发送 ID,并选择员工可以执行的服务并将它们存储在表中。我已插入员工 ID 和服务 ID。现在我需要插入员工姓名。
我的控制器文件是
class admin_service_limitation extends CI_Controller{
public function services()
{
$id = $this->session->userdata('employee');
$id_array = $this->input->post("services");
//I need to get the employee name here and store them in a table along with employee id and service id
for ($i = 0; $i < count($id_array); $i++) {
if(isset($id_array[$i])&& $id_array[$i]!=""){
$data_to_store = array('employee_id' => $id, 'service_id' => $id_array[$i]);
$this->add_service_model->save($data_to_store);
}
}
$data['addservice'] = $this->add_service_model->get_addservices();
$data['main_content'] = 'admin/service_limitation/newview';
$this->load->view('includes/template', $data);
}
我在这里获取员工 ID 和服务 ID 并将它们存储在一个表中。该表包含 employee_id、employee_name 和 service_id 等字段。
我的模型文件:
class sample_model extends CI_Model{
function store_service($data)
{
$insert = $this->db->insert('service', $data);
return $insert;
}
}
在这里,我编写了一个函数,用于插入addservice 表。我将所有数据存储为数组并将它们保存在addservice 表中。
我在其中选择员工的视图文件。
select.php
<?php
echo form_open('admin/service_limitation/service_view/'.$this->uri->segment(4).'', $attributes);
?>
<table class="table table-striped table-bordered table-condensed">
<thead>
<tr>
<th class="header">Employee id</th>
<th class="yellow header headerSortDown">First name</th>
<th class="green header">Last name</th>
<th class="red header">Email</th>
<th class="red header">Chair renter</th>
<th class="red header">Actions</th>
</tr>
</thead>
<tbody>
<?php
foreach($employee as $row)
{
echo '<tr>';
echo '<td>'.$row['id'].'</td>';
echo '<td>'.$row['emp_first_name'].'</td>';
echo '<td>'.$row['emp_last_name'].'</td>';
echo '<td>'.$row['emp_email_id'].'</td>';
echo '<td>'.$row['chair_renter'].'</td>';
echo '<td class="crud-actions">
<a href="'.site_url("admin").'/service_limitation/service_view/'.$row['id'].'" class="btn btn-info">Select employee</a>
</td>';
echo '</tr>';
}
?>
</tbody>
</table>
<?php echo form_close(); ?>
在这个视图中,我有一个表单,一旦我提交表单,员工 ID 将被发送到控制器功能,这里我现在需要发送员工姓名.. 有人可以帮我编码吗?
我选择服务的另一个视图是:service_view.php
<?php
$attributes = array('class' => 'form-inline reset-margin', 'id' => '');
echo form_open('admin/service_limitation/newview', $attributes);
?>
<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">
<input type="checkbox" value="'.$row['id'].'" name="services[]"/>
</td>';
echo '</tr>';
}
?>
</tbody>
</table>
<button class="btn btn-primary" type="submit">Save changes</button>
<button class="btn" type="reset">Cancel</button>
</div>
<?php echo form_close(); ?>
上面的视图调用了我的控制器文件中的服务函数,通过它我可以保存数据,例如第一个视图中的员工ID和第二个视图中的服务ID。
编辑 01
public function select_service($id)
{
$this->load->library('session');
$this->session->set_userdata('employee', $id);
$data['service'] = $this->add_service_model->get_services();
$data['main_content'] = 'admin/service_limitation/service_view';
$this->load->view('includes/template', $data);
}
这是一个函数,我将员工 ID 作为会话变量并在上面的选择函数中使用它们。是否可以像我得到employee_id一样得到员工姓名。
【问题讨论】:
-
看不懂问题
-
我需要发送我的员工姓名和员工 id.here,选择员工
-
在
.$row['id']中它将所有数据传递到表中,那么您如何选择一个?否则使用下拉菜单 -
如果它通过了所有数据,我可以在这里获取员工姓名吗?
-
没办法。或先提示文本框输入emp编号或名称。(必须唯一)。当用户输入正确的加载相关员工数据时。
标签: php mysql codeigniter controller arguments