下拉列表值不会显示在codeigniter

时间:2016-12-03 12:01:01

标签: php mysql codeigniter drop-down-menu

下拉值不会显示在运行

时仅显示的错误下方
  

遇到PHP错误严重性:通知消息:未定义   property:Timesheet :: $ Timesheet_modal文件名:   controllers / Timesheet.php行号:17 Backtrace:文件:   F:\ xampp \ htdocs \ VEFM-TS \ application \ controllers \ Timesheet.php行:17   功能:_error_handler文件:F:\ xampp \ htdocs \ VEFM-TS \ index.php行:   315功能:require_once致命错误:调用成员函数   get_div()on null in   F:\ xampp \ htdocs \ VEFM-TS \ application \ controllers \ Timesheet.php在线   17遇到PHP错误严重性:错误消息:调用a   成员函数get_div()on null文件名:controllers / Timesheet.php   行号:17 Backtrace:

控制器文件

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Timesheet extends CI_Controller {

    function __construct(){
        parent::__construct();
            $this->load->library('form_validation');
            $this->load->library('session');
    }

    public function index()
    {
            if (!$this->session->userdata('login_data')) {
                redirect('Login');
            }else{
                $datas['division'] = $this->Timesheet_modal->get_div();
                $datas['customer'] = $this->Timesheet_modal->get_customer();
                print_r($datas);
                $this->load->view('user/timesheet_add', $datas);
            } 
            // $this->load->view('user/home');
    }


}


?>

模型文件

<?php
class Timesheet_modal extends CI_Model {

     public function __construct() 
     {
           parent::__construct(); 
           $this->load->database();
           $this->load->library('session');

     }

    function get_div(){
        $this->db->select("*");
        $this->db->from('vefm_comp_division');
        $query = $this->db->get();
        $result = $query->result();
        print_r($result);
        return $result;
    }

    function get_customer(){
        $this->db->select("*");
        $this->db->from('vefm_client_details');
        $query = $this->db->get();
        $result = $query->result();

        return $result;
    }


}
?>

查看文件

<select  class="form-control required"  name="division" id="division" required>
<option disabled selected >Select Division</option>
    <?php
     foreach($division as $div ){
         echo '<option value="'.$div->id.'">'.$div->division_name.'</option>';
     }
    ?>
</select>
<select  class="form-control required"  name="unit" id="unit" required>
<option disabled selected >Select Division</option>
    <?php
     foreach($unit as $unitid ){
         echo '<option value="'.$unitid->id.'">'.$unitid->unit_name.'</option>';
     }
    ?>
</select>

1 个答案:

答案 0 :(得分:2)

在访问模态函数之前初始化模态

public function index()
{
        if (!$this->session->userdata('login_data')) {
            redirect('Login');
        }else{
            $this->load->model("Timesheet_modal");
            $datas['division'] = $this->Timesheet_modal->get_div();
            $datas['customer'] = $this->Timesheet_modal->get_customer();
            print_r($datas);
            $this->load->view('user/timesheet_add', $datas);
        } 
     }