在codeigniter中调用控制器函数

时间:2016-04-01 16:56:14

标签: php html mysql codeigniter

我'我仍然是codeigniter的初学者,我想调用控制器的功能,但我不知道为什么我总是得到404 error

错误: error

这是视图代码

<?php foreach ($records  as $new_Employee):
    ?>
    <form class="form-horizontal"    ?>
                <div class="col-lg-5">
                    <div class="media">
                        <a class="pull-left" href="#">
                            <img class="media-object dp img-circle"  src="../assets/img/avatar5.png" style="width: 100px;height:100px;">
                        </a>
                        <div class="media-body">
                            <h4 class="media-heading"> <?php echo $new_Employee["name_Employee"]; ?> <small> <?php echo $new_Employee["nationality_Employee"]; ?></small></h4>
                            <h5><?php echo $new_Employee["email"]; ?> </h5>
                            <hr style="margin:8px auto">
                            <table cellpadding="50px">
                                <tr>
                           <td> <p data-placement="top" data-toggle="tooltip" title="Edit"><button class="btn btn-primary btn-xs" data-title="Edit" data-toggle="modal" data-target="#edit" ><span class="glyphicon glyphicon-pencil"></span></button></p></td>
                           <td>  <p data-placement="top" data-toggle="tooltip" title="Delete"><button class="btn btn-danger btn-xs" data-title="Delete" data-toggle="modal" data-target="#delete"   ><span class="glyphicon glyphicon-trash"></span></button></p></td>
                              <td> <a class="btn btn-danger" href="<?php echo site_url('PdgDashboard/deleteEmployee'.$new_Employee['name_Employee']);  ?>"></a></td>
                                </tr>
                            </table>
                        </div>
                    </div>

                </div>

    </form>
<?php
endforeach; ?>

这是我打电话的控制器

 class PdgDashboard extends CI_Controller {
     public function index($data)
{
    $data['pseudo_Empoyee'] = $data['new_Employee']['pseudo_Empoyee'];
    $data['nationality_Employee'] = $data['new_Employee']['nationality_Employee'];
    $data['tel_Employee'] = $data['new_Employee']['tel_Employee'];
    $this->load->view('Template/Pdg_Default_Page');


}


     public function __construct()
     {
         parent::__construct();
         $this->load->model('employee');
         $this->load->helper('url_helper');
         $this->load->model('absence');
         $this->load->model('lieve');

     }

     public function EmployeeMang( ){
$this->load->library('pagination');
         $config["base_url"]="http://localhost/GRH/PdgDashboard/EmployeeMang";
         $config['total_rows'] =$this->db->get("cs_employee")->num_rows();
         $config['per_page'] =3;
         $config['num_links'] = 10;
         $this->pagination->initialize($config);
         $data['records']=$this->db->select('*')->get('cs_employee', $config['per_page'],$this->uri->segment(3))->result_array();

         $data['links']  = $this->pagination->create_links();

         $this->load->view('pages/Employee_Manag', $data);
            /* $data['new_Employee'] = $this->employee->get_Employee();
             if (empty($data['new_Employee']))
             {
                 show_404();
             }


         $this->load->view('pages/Employee_Manag', $data);

      //   $this->load->view('pages/Employee_Manag', $data);*/

     }
     public  function searchEmployee(){
         if($this->input->post('search')!="")
         {
         $this->load->library('pagination');
         $confi["base_url"]="http://localhost/GRH/PdgDashboard/searchEmployee";

         $confi['per_page'] =3;
         $confi['num_links'] = 10;
         $this->pagination->initialize($confi);

         $search_term = $this->input->post('search');
         $data['rec']= $this->db->where('name_Employee',$search_term)->get('cs_employee', $confi['per_page'],$this->uri->segment(3))->result_array();
         $config['total_rows'] = sizeof($data['rec']);
         // Use a model to retrieve the results.
    //     $data['rec'] = $this->employee->searchEmployee($search_term);

         // Pass the results to the view.
         $data['link']  = $this->pagination->create_links();
         $this->load->view('pages/search', $data);}
         else
             $this->EmployeeMang();
     }
public  function createEmployee(){

    $this->load->helper('form');
    $this->load->library('form_validation');

    $this->form_validation->set_rules('txtFirstName', 'Text', 'required');
    $this->form_validation->set_rules('txtLastName', 'Text', 'required');
    $this->form_validation->set_rules('txtCin', 'Text', 'required');
    $this->form_validation->set_rules('date', 'Text', 'required');
    $this->form_validation->set_rules('ComboCountry', 'Text', 'required');

    $this->form_validation->set_rules('txtEmail', 'Text', 'required');
    $this->form_validation->set_rules('txtphone', 'Text', 'required');
    $this->form_validation->set_rules('txtAddress', 'Text', 'required');
    $this->form_validation->set_rules('txtPostal', 'Text', 'required');
    $this->form_validation->set_rules('Training', 'Text', 'required');
    $this->form_validation->set_rules('Startdate', 'Text', 'required');
    $this->form_validation->set_rules('txtBank', 'Text', 'required');
    $this->form_validation->set_rules('comboStatus', 'Text', 'required');
    $this->form_validation->set_rules('Startdate', 'Text', 'required');




    $this->employee->createEmployee();
    $data['new_Employee'] = $this->employee->get_Employee();

    $this->EmployeeMang();
    //TODO link between data base and form keys


}

     public function deleteEmployee($EmployeeName){
    $this->load->model('employee');
  $this->emloyee->deleteEmployee($EmployeeName);
      $this->EmployeeMang();
     }
     public function PayoutRequest(){

         $this->load->view('pages/Advance_Payment_Reques');


     }
     public function  Recruitement(){

         $this->load->view('pages/Recruitement');


     }
     public function Announce(){

         $this->load->view('pages/announcement');

     }
     public function Holiday_Requests(){

         $this->load->view('pages/HolidaysPosts');

     }

     public function absence(){

         $this->load->view('pages/AbsenceConsult');

     }
     public function Leave_Requests(){

         $this->load->view('pages/Leave_Requests');


     }
     public function Profile_Employee(){

         $this->load->view('pages/Profile_Employee');

     }

   public function Post_Managment(){

       $this->load->view('pages/Post_Managment');


   }

     public function displayAbsence(){
         $this->load->library('pagination');
         $config["base_url"]="http://localhost/GRH/PdgDashboard/displayAbsence";
         $config['total_rows']=sizeof($this->absence->getAbsence());
         $config['per_page'] =3;
         $config['num_links'] = 3;
         $this->pagination->initialize($config);
         $data['records']=$this->db->select('*')->get('cs_absence', $config['per_page'],$this->uri->segment(3))->result_array();

         $data['links']  = $this->pagination->create_links();

         $this->load->view('pages/AbsenceConsult', $data);

     }

  public function   searchAbcense()
  {   $search_term = $this->input->post('search');
      if($search_term!="") {
          $this->load->library('pagination');
          $confi["base_url"] = "http://localhost/GRH/PdgDashboard/ searchAbcense";

          $confi['per_page'] = 3;
          $confi['num_links'] = 10;
          $this->pagination->initialize($confi);


          $data['records'] = $this->db->where('id_Employee_absence', $search_term)->get('cs_absence', $confi['per_page'], $this->uri->segment(3))->result_array();
          $config['total_rows'] = sizeof($data['records']);
          // Use a model to retrieve the results.
          //     $data['rec'] = $this->employee->searchEmployee($search_term);

          // Pass the results to the view.
          $data['links'] = $this->pagination->create_links();
          $this->load->view('pages/AbsenceConsult', $data);
      }
      else $this->displayAbsence();

 }

     public function displayLieve(){
         $this->load->library('pagination');
         $config["base_url"]="http://localhost/GRH/PdgDashboard/displayLieve";
         $config['total_rows']=sizeof($this->lieve->getLieve());
         $config['per_page'] =3;
         $config['num_links'] = 3;
         $this->pagination->initialize($config);
         $data['records']=$this->db->select('*')->get('cs_lieve', $config['per_page'],$this->uri->segment(3))->result_array();

         $data['links']  = $this->pagination->create_links();

         $this->load->view('pages/HolidaysPosts', $data);

     }


     public function   searcLieve()
     {   $search_term = $this->input->post('search');
         if($search_term!="") {
             $this->load->library('pagination');
             $confi["base_url"] = "http://localhost/GRH/PdgDashboard/searcLieve";

             $confi['per_page'] = 3;
             $confi['num_links'] = 10;
             $this->pagination->initialize($confi);


             $data['records'] = $this->db->where('id_Employee_lieve', $search_term)->get('cs_lieve', $confi['per_page'], $this->uri->segment(3))->result_array();
             $config['total_rows'] = sizeof($data['records']);
             // Use a model to retrieve the results.
             //     $data['rec'] = $this->employee->searchEmployee($search_term);

             // Pass the results to the view.
             $data['links'] = $this->pagination->create_links();
             $this->load->view('pages/HolidaysPosts', $data);
         }
         else $this->displayLieve();

     }

 }

我从模型中调用的函数是:

public function deleteEmployee($emloyeeName){
//    $this->db->delete('cs_employee', array('name_Employee' => $emloyeeName));
    $this->db->where('name_Employee', $emloyeeName);
    $this->db->delete('cs_employee');
}

1 个答案:

答案 0 :(得分:3)

您的视图文件中存在错误:在删除网址中缺少/

您的代码:

<a class="btn btn-danger" href="<?php echo site_url('PdgDashboard/deleteEmployee'.$new_Employee['name_Employee']);  ?>"></a>

正确的代码是:

<a class="btn btn-danger" href="<?php echo site_url('PdgDashboard/deleteEmployee/'.$new_Employee['name_Employee']);  ?>"></a>
删除功能

后,在链接中添加/
site_url('PdgDashboard/deleteEmployee/'.$new_Employee['name_Employee']);