大家好,我想问为什么我的控制器不能在视图中加载?但是我已经声明了变量这是我的代码
在该视图中,数据未显示并给出错误未定义变量,但已声明
<div class="col-sm-8">
<input type="text" class="form-control" data-user="user" value="<?php echo $jabatan->nama_jabatan; ?>" readonly>
</div>
这是我的控制器我认为在那里没有加载数据
function __construct()
{
parent::__construct();
$this->load->model('jabatan_model'); //sejajarlevel
$this->load->model('jenis_biaya_model'); //sejajarbook
$this->load->model('penerimaan_model'); //sejajarcustomer
}
public function index()
{
if($this->session->userdata('id_user') != Null)
{
$id = $this->session->userdata('id_jabatan');
$data = array(
'kode_bayar' => $this->pembayaran_model->invoice_no(),
'total' => $this->show_total(),
'jabatan' => $this->jabatan_model->jabatan_getById($id)->row(),
'jenis_biaya' => $this->jenis_biaya_model->jenis_biaya_getAll(),
'penerimaan' => $this->penerimaan_model->penerimaan_getAll(),
);
$this->load->view('admin/pembayaran/v_Pembayaran', $data);
} else {
$load = $this->load->view('auth/login');
echo '<script language=JavaScript>alert("Anda Belum Login, Silahkan Login")
onclick=location.href="auth" </script>';
}
}
这是我的型号
<?php defined('BASEPATH') or exit ('No direct script access allowed');
class Pembayaran_model extends CI_model
{
public function jenis_biaya_getAll()
{
$query = $this->db->query("SELECT * FROM jenis_biaya");
return $query;
}
public function jenis_biaya_getById($id)
{
$query = $this->db->query("SELECT * FROM jenis_biaya where id_jenis_biaya=$id");
return $query;
}
public function min_stock($qty, $id_jenis_biaya)
{
$query = $this->db->query("UPDATE jenis_biaya SET stock=stock-$qty
Where id_jenis_biaya=$id_jenis_biaya");
return $query;
}
public function plus_stock($qty, $id_jenis_biaya)
{
$query = $this->db->query("UPDATE jenis_biaya SET stock=stock+$qty
Where id_jenis_biaya=$id_jenis_biaya");
return $query;
}
public function invoice_no()
{
$query = $this->db->query("SELECT MAX(pembayaran_id) as invoice_no from pembayaran");
if ($query->num_rows() > 0) {
$row = $query->row();
$n = ((int) $row->invoice_no) + 1;
$no = sprintf("%09s", $n);
} else {
$no = sprintf("%09s", 1);
}
$kode_bayar = "BYR" . $no;
return $kode_bayar;
}
public function pembayaran_insert($table, $data)
{
$query = $this->db->insert($table, $data);
return $query;
}
public function pembayaran_last_id()
{
$query = $this->db->query("SELECT MAX(pembayaran_id) as pembayaran_id FROM pembayaran");
return $query->row();
}
public function d_pembayaran_insert($table, $data)
{
$query = $this->db->insert($table, $data);
return $query;
}
}
感谢的帮助
<?php print_r($jabatan); ?>
使用上面的行检查数组是否来自控制器。