视图中的按钮不会在控制器中调用方法

时间:2015-10-07 19:03:54

标签: php html model-view-controller

我遇到了一个问题:我有一个视图,需要在我的控制器EmployeeController中调用一个方法来转到添加员工的页面。但它不起作用..也适用于其它观点

这是观点:

<body>
         <form class="form-horizontal" id='employeeform' id='employeeform' action="<?php echo base_url();?>EmployeeController/addEmployee" method="post">
          <div class="container">
          <div class="row">
          <div class="col-lg-12 col-sm-12">
               <table class="table table-striped table-hover">
                    <thead>
                         <tr>
                              <th>#</th>
                              <th>ID</th>
                              <th>Naam werknemer</th>
                          <th>Datum aanwerving</th>
                          <th>Salaris</th>

                     </tr>
                </thead>
                <tbody>
                     <?php for ($i = 0; $i < count($employeelist); ++$i) { ?>
                          <tr>
                               <td><?php echo ($i+1); ?></td>
                               <td><?php echo $employeelist[$i]->employee_no; ?></td>
                               <td><?php echo $employeelist[$i]->employee_name; ?></td>
                               <td><?php echo $employeelist[$i]->hired_date; ?></td>
                               <td><?php echo $employeelist[$i]->salary; ?></td>
                          </tr>
                     <?php } ?>
                </tbody>
           </table>
        <input id="btn_add" name="btn_add" type="submit" class="btn btn-primary" value="Add employee" />
      </div>
      </div>
      </div>
      </form>
     </body>

这是控制器:

类EmployeeController扩展了CI_Controller {

public function __construct() {
    parent::__construct();
    $this->load->library('session');
    $this->load->helper('form');
    $this->load->helper('url');
    $this->load->database();
    $this->load->library('form_validation');
    //load the employee model
    $this->load->model('employee_model');
}

//index function
function index() {
    $employeelist = $this->employee_model->get_employee_list();
    $data['employeelist'] = $employeelist;
    $this->load->view('employee/employee_add', $data);
}

function createEmployee() {
    $this->form_validation->set_rules('employee_no', 'Employee No', 'trim|required|numeric');
    $this->form_validation->set_rules('employee_name', 'Employee Name', 'trim|required|xss_clean|callback_alpha_only_space');
    $this->form_validation->set_rules('hired_date', 'Hired Date', 'required');
    $this->form_validation->set_rules('salary', 'Salary', 'required|numeric');

    if ($this->form_validation->run() == FALSE) {
        //fail validation
        $this->load->view('employee/employee_add');
    } else {
        //pass validation
        $data = array(
            'employee_no' => $this->input->post('employeeno'),
            'employee_name' => $this->input->post('employeename'),
            'hired_date' => @date('Y-m-d', @strtotime($this->input->post('hireddate'))),
            'salary' => $this->input->post('salary'),
        );

        //insert the form data into database
        $this->db->insert('tbl_employee', $data);

        //display success message

        $employeeresult = $this->employee_model->get_employee_list();
        $data['employeelist'] = $employeeresult;
        //load the department_view
        $this->load->view('employee/employee_view', $data);
        redirect('employee/employee_view');
    }
}

function addEmployee() {
    $this->load->view('employee/employee_add');
    //set validation rules
}
}
?>

我得到的错误是:     在此服务器上找不到请求的URL /BoMaTec_afstudeerproject/CodeIgniter-3.0.1/EmployeeController/createEmployee。

1 个答案:

答案 0 :(得分:0)

好像你没有任何路由器那个网址,或路由器是错误的。根据错误,它正在尝试加载名为EmployeeController的文件夹,并在该文件夹中加载另一个名为createEmployee的文件夹。检查您正在使用的框架中的.htaccess文件和路由器。