Welcome Guest, Not a member yet? Register   Sign In
Trying to access array offset on value of type null
#1

i'm having a problem on line 29 stating "Trying to access array offset on value of type null"

even though in the view it appears and there are no errors. just throws an error
Message: Trying to access array offset on value of type null

Filename: controllers/Outgoing.php

Line Number: 29

at the top of the header
Message Error
[Image: error-line-29.png]

Full Error In View
[Image: full-error.png]


Error Line Number 29 in Controller : 
PHP Code:
$stok $this->admin->get('barang', ['id_barang' => $input])['stok']; 


My Controller :
PHP Code:
<?php
defined
('BASEPATH') or exit('No direct script access allowed');

class 
Barangkeluar extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
        cek_login();

        $this->load->model('Admin_model''admin');
        $this->load->library('form_validation');
    }

    public function index()
    {
        $data['title'] = "Barang keluar";
        $data['barangkeluar'] = $this->admin->getBarangkeluar();
        $this->template->load('templates/dashboard''barang_keluar/data'$data);
    }

    private function _validasi()
    {
        $this->form_validation->set_rules('tanggal_keluar''Tanggal Keluar''required|trim');
        $this->form_validation->set_rules('karyawan_id''Karyawan''required');
        $this->form_validation->set_rules('barang_id''Barang''required');

        $input $this->input->post('barang_id'true);
        $stok $this->admin->get('barang', ['id_barang' => $input])['stok'];
        $stok_valid $stok 1;

        $this->form_validation->set_rules(
            'jumlah_keluar',
            'Jumlah Keluar',
            "required|trim|numeric|greater_than[0]|less_than[{$stok_valid}]",
            [
                'less_than' => "Jumlah Keluar tidak boleh lebih dari {$stok}"
            ]
        );
    }

    public function add()
    {
        $this->_validasi();
        if ($this->form_validation->run() == false) {
            $data['title'] = "Barang Keluar";
            $data['karyawan'] = $this->admin->get('karyawan');
            $data['barang'] = $this->admin->get('barang'null, ['stok >' => 0]);

            // Mendapatkan dan men-generate kode transaksi barang keluar
            $kode 'T-BK-' date('ymd');
            $kode_terakhir $this->admin->getMax('barang_keluar''id_barang_keluar'$kode);
            $kode_tambah substr($kode_terakhir, -55);
            $kode_tambah++;
            $number str_pad($kode_tambah5'0'STR_PAD_LEFT);
            $data['id_barang_keluar'] = $kode $number;

            $this->template->load('templates/dashboard''barang_keluar/add'$data);
        } else {
            $input $this->input->post(nulltrue);
            $insert $this->admin->insert('barang_keluar'$input);

            if ($insert) {
                set_pesan('data berhasil disimpan.');
                redirect('barangkeluar');
            } else {
                set_pesan('Opps ada kesalahan!');
                redirect('barangkeluar/add');
            }
        }
    }

    public function delete($getId)
    {
        $id encode_php_tags($getId);
        if ($this->admin->delete('barang_keluar''id_barang_keluar'$id)) {
            set_pesan('data berhasil dihapus.');
        } else {
            set_pesan('data gagal dihapus.'false);
        }
        redirect('barangkeluar');
    }
}

Reply




Theme © iAndrew 2016 - Forum software by © MyBB