简体   繁体   中英

call a controller function in codeigniter

i ' m still a beginner in codeigniter and i want to call a function of a controller but i don't know why i always get 404 error

Error: 错误

this is the view code

<?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; ?>

this is the controller that i called

 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();

     }

 }

the function that i called from the model is :

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

there is an error in your View file : missing / in delete url

your code :

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

correct code is :

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

add / in your link after delete function

site_url('PdgDashboard/deleteEmployee/'.$new_Employee['name_Employee']);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM