我是codeigniter的新手。我在自定义库中访问数组数据时遇到了一些问题。
我的模特
<?php if( ! defined('BASEPATH'))exit('No direct script access allowed');
class Laporan_Gaji_M extends CI_Model {
function __construct() {
parent::__construct();
$this->load->library("Payroll");
$this->load->library("Payroll_J");
$this->load->library("Payroll_G");
}
function data_ku()
{
$sql = "SELECT a.idx, a.kode, a.jenis, a.nama, a.tgl_masuk,
a.status_karyawan, a.kelamin, a.status_tk, a.tunj_tetap,
a.tunj_jabatan, a.tunj_keahlian, a.medical_housing, a.upah_lembur,
a.gaji, c.nama AS nama_jabatan, a.kd_finger, b.* FROM
hrd_master_pegawai AS a LEFT JOIN hrd_laporan_absensi AS b ON
a.kd_finger = b.kode_finger AND b.bulan = '$bulan' LEFT JOIN
hrd_master_jabatan AS c ON a.jabatan = c.id_jabatan";
$row = $this->db->query($sql);
foreach ($row->result_array() as $value) {
//print_r($value["jenis"]);
$data = new Payroll_G($value); // i try send to my custom library and access the arrays data but not working.
}
}
}
我尝试在模型中获取$value["jenis"]
并正常工作,
但是当我尝试在自定义库中获取$value["jenis"]
时。我收到了消息
严重性:注意 消息:未定义的索引:jenis 文件名:libraries / Payroll_G.php **
此处是我的自定义库
<?php
class Payroll_G extends Payroll {
function __construct($value = array()) {
parent::__construct();
$this->hitung($value);
}
function hitung($value) {
print_r($value["jenis"]);
// message => Undefined index: jenis
}
}
提前谢谢
答案 0 :(得分:0)
当您最初在Models的构造中加载库时会发生错误,因为$ value为空。并且您还在循环内重复初始化类。
我建议您使用codeigniter的函数调用约定:
型号:
foreach ($row->result_array() as $value) {
$data = $this->Payroll_G->hitung($value);
}
库:
class Payroll_G extends Payroll {
function __construct() {
parent::__construct();
}
function hitung($value=array()) {
print_r($value["jenis"]);
}
}