0
votes

dropdown values are not displayed below error only shown while running

A PHP Error was encountered Severity: Notice Message: Undefined property: Timesheet::$Timesheet_modal Filename: controllers/Timesheet.php Line Number: 17 Backtrace: File: F:\xampp\htdocs\VEFM-TS\application\controllers\Timesheet.php Line: 17 Function: _error_handler File: F:\xampp\htdocs\VEFM-TS\index.php Line: 315 Function: require_once Fatal error: Call to a member function get_div() on null in F:\xampp\htdocs\VEFM-TS\application\controllers\Timesheet.php on line 17 A PHP Error was encountered Severity: Error Message: Call to a member function get_div() on null Filename: controllers/Timesheet.php Line Number: 17 Backtrace:

controller file

<?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');
    }


}


?>

model file

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


}
?>

view file

<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

1 Answers

2
votes

initialize modal before accesing modal functions

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