Search code examples
phpcodeigniter

Pass data from function to other function in ci3


I have 2 function like this

class Infograph extends CI_Controller
{
    public function index()
    {
    $wilayah = $this->input->post('wilayah', TRUE);
        $kodeSubWilayah = $this->input->post('subWilayah', TRUE);

        if ($kodeSubWilayah) {
            $kodeSubWilayah = $this->encryption->decrypt($kodeSubWilayah);
            if ($kodeSubWilayah === false) {
                redirect('test/404');
            }
        }

        if ($wilayah) {

            $data['wilayah'] = strtolower($wilayah);
        }

        if ($kodeSubWilayah) {
            $data['subWilayah'] = $db2->query("SELECT * FROM provinsi WHERE id = ?", [$kodeSubWilayah])->result_array();
        } 
    }

    public function export()
    {
        // i want to send data $data['wilayah'] and $data['subWilayah']
    }

}

How can i pass the data into the export fucntion? i want to get the $data['wilayah'] and $data['subWilayah']


Solution

  • use function parameters public function export($datawilayah,$datasubWilayah)

    call the export function inside index function like $this->export($data['wilayah'],$data['subwilayah'])