消息:未定义的变量:get

时间:2015-02-12 14:23:08

标签: php codeigniter

我试图加入我的桌子并开始工作,但我不知道为什么会收到以下错误消息。

A PHP Error was encountered
Severity: Notice
Message: Undefined variable: get
Filename: views/tambah_wali.php
Line Number: 13

Fatal error: Call to a member function result() on a non-object in C:\xampp\htdocs\ujikom_sekolah\application\views\tambah_wali.php on line 13

这是我的控制者:

public function tambah_wali($kode){

    $data['get']=$this->madm->join_wali_siswa($kode);
    $this->load->view('tambah_wali');
}

这是我的模特:

public function join_wali_siswa($kode) {

    $this->db->select('wali_murid.nisn');
    $this->db->from('siswa');
    $this->db->join('wali_murid','siswa.nisn=wali_murid.nisn','right');
    $this->db->where('siswa.nisn',$kode);
    $query=$ambildata=$this->db->get();
    if($ambildata->num_rows > 0)
        return $query;
    else
        return null;
    }

这是我的观点第13行:

<?php foreach($get->result() as $row): ?>

1 个答案:

答案 0 :(得分:1)

如果有$ data变量必须将其添加到以下视图中,那么在您的视图中加载$data['get']似乎会丢失。

$data['get'] = $this->madm->join_wali_siswa($kode);

$this->load->view('tambah_wali', $data);