我需要在表中插入员工和服务ID

时间:2015-06-29 10:02:13

标签: php mysql codeigniter

我需要将员工ID和服务ID插入到新表中addservice.i在我的控制器页面中写了一个函数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>

这段代码不起作用。如果有人纠正我的代码,我无法解决我的问题。

1 个答案:

答案 0 :(得分:0)

在你的网址中尝试在projectname http://localhost/elfanto/index.php/elfanto_billing/admin/addservice之后添加index.php,并且该链接与这些功能不匹配。

示例

http://localhost/project/index.php/controller/add/

首先我建议自动加载会话库以获取

要获得任何设置会话用户数据,您需要做一些事情,但不知道如何设置会话。

$this->session->userdata('total')

控制器功能

public function add() {
    $this->selected_model->store_employee();

    $data['main_content'] = 'admin/selected/list';
    $this->load->view('includes/template', $data);  

}

模型功能

public function store_employee()
{

    $data = array(
        'employee_id' => $this->session->userdata('total'),
        'service_id' => $this->uri->segment(4)
    );

    $this->db->insert('addservice', $data);

}

如果在array()中设置会话

$taxdetails = $this->session->userdata('some_array_name');

$taxdetails['total']

功能示例2

public function store_employee()
{

$taxdetails = $this->session->userdata('some_array_name');

    $data = array(
        'employee_id' => $taxdetails['total'],
        'service_id' => $this->uri->segment(4)
    );

    $this->db->insert('addservice', $data);

}