2016-01-04 3 views
0

Я пытаюсь отредактировать запись. Теперь в моем Баттоне я пропускание в EMP_ID, как URI, но он принимает идентификатор и редактирует на этой основе:Почему Редактор URI не работает правильно Codeigniter Code?

Смотрите это мой код:

public function edit($emp_id = NULL) 
{ 


    if ($emp_id) 
       { 
        $this->data['user'] = $this->user_m->get($emp_id); 
        count($this->data['user']) || $this->data['errors'][] = 'User could not be found'; 


        echo $emp_id; 



        // Set up the form 
        $rules = $this->user_m->rules_admin; 
        $id || $rules['password']['rules'] .= '|required'; 
        $this->form_validation->set_rules($rules); 

          // Process the form 
        if ($this->form_validation->run() == TRUE) 
        { 

         $data = $this->user_m->array_from_post(array('emp_id','name','last_name','email','password','phone','gender','designation','user_type','blood_group','date_birth','status','address')); 


         $data['password'] = $this->user_m->hash($data['password']); 

         $key=$this->user_m->save($data, $id); 

         redirect('admin/user/index'); 
        } 


       } 

       // Load the view 

       echo $this->db->last_query(); 
       $this->data['subview'] = 'employee/profile/edit'; 
       $this->load->view('employee/_layout_main', $this->data); 
       } 

И это мое мнение:

 <table class="table table-striped table-hover"> 
      <thead> 
       <tr> 


        <th>Employee_Id</th> 
        <th>Name</th> 
        <th>Last_Name</th> 
        <th>Email</th> 
        <th>Phone</th> 
        <th>Gender</th> 
        <th>Designation</th> 
        <th>User Type</th> 
        <th>Blood Group</th> 
        <th>Date of Birth</th> 
        <th>Status</th> 

        <th>Edit</th> 



       </tr> 
      </thead> 
      <tbody> 
    <?php if(count($users)): foreach($users as $user): ?> 
       <tr class="active"> 


     <td><?php echo anchor('admin/user/edit/' . $user->emp_id, $user->emp_id); ?></td> 
     <td><?php echo anchor('admin/user/edit/' . $user->emp_id, $user->name); ?></td> 
     <td><?php echo anchor('admin/user/edit/' . $user->emp_id, $user->last_name); ?></td> 
     <td><?php echo anchor('admin/user/edit/' . $user->emp_id, $user->email); ?></td> 
     <td><?php echo anchor('admin/user/edit/' . $user->emp_id, $user->phone); ?></td> 
     <td><?php echo anchor('admin/user/edit/' . $user->emp_id, $user->gender); ?></td> 
     <td><?php echo anchor('admin/user/edit/' . $user->emp_id, $user->designation); ?></td> 
     <td><?php echo anchor('admin/user/edit/' . $user->emp_id, $user->user_type); ?></td> 
     <td><?php echo anchor('admin/user/edit/' . $user->emp_id, $user->blood_group); ?></td> 
     <td><?php echo anchor('admin/user/edit/' . $user->emp_id, $user->date_birth); ?></td> 
     <td><?php echo anchor('admin/user/edit/' . $user->emp_id, $user->status); ?></td> 


        <td><?php echo btn_edit('employee/profile/edit/' . $user->emp_id); ?></td> 

       </tr> 
     <?php endforeach; ?> 
     <?php else: ?> 
       <tr> 
        <td colspan="3">We could not find any users.</td> 
       </tr> 
     <?php endif; ?> 
       </tbody> 
      </table> 
     </section> 


     <?php $this->load->view('admin/components/page_tail') ?> 

Теперь, когда я нажимаю на свою кнопку редактирования, URL-адрес правильный.

http://127.0.0.1/project/admin/user/edit/21 

, но я редактирую строки с ID = 21 вместо emp_id = 21.

Я не могу понять, ошибка в моем коде, пожалуйста, помогите

MY_MODEL

:

public function get($id = NULL, $single = FALSE){ 

    if ($id != NULL) { 
     $filter = $this->_primary_filter; 
     $id = $filter($id); 
     $this->db->where($this->_primary_key, $id); 
     $method = 'row'; 
    } 
    elseif($single == TRUE) { 
     $method = 'row'; 
    } 
    else { 
     $method = 'result'; 
    } 


    return $this->db->get($this->_table_name)->$method(); 
} 

public function get_by($where, $single = FALSE){ 
    $this->db->where($where); 
    return $this->get(NULL, $single); 
} 

public function save($data, $id = NULL){ 




    // Set timestamps 
    if ($this->_timestamps == TRUE) { 
     $now = date('Y-m-d H:i:s'); 
     $id || $data['created'] = $now; 
     $data['modified'] = $now; 
    } 

    // Insert 
    if ($id === NULL) { 
     !isset($data[$this->_primary_key]) || $data[$this->_primary_key] = NULL; 
     $this->db->set($data); 
     $this->db->insert($this->_table_name); 
     $id = $this->db->insert_id(); 
    } 
    // Update 
    else { 
     $filter = $this->_primary_filter; 
     $id = $filter($id); 
     $this->db->set($data); 
     $this->db->where($this->_primary_key, $id); 
     $this->db->update($this->_table_name); 
    } 

    return $id; 
} 

ответ

0

Вы можете написать это

<td><?php echo btn_edit('employee/profile/edit/' . $user->emp_id); ?></td> 

вместо

<td><?php echo btn_edit('employee/profile/edit/' . $user->id); ?></td> 
+0

я написал для этого, но до сих пор не работает – Rajan

+0

он возвращает правильный URI, но когда я изменить это показывает данные о ID = 21 вместо он должен вернуть EMP_ID = 21 – Rajan

+0

проверить свою модельную функцию, когда данные передачи должны обновляться, а не сохранять –

1

проверьте контрольный массив $ users в контроллере

echo print_r ($ users);

он будет печатать весь массив

пользователя Это может помочь вам отслеживать точные данные

Смежные вопросы