-3

Possible Duplicate:
“PHP Notice: Undefined property”

I try to use external library in my CI web. I refer these links https://www.codeigniter.com/user_guide/general/creating_libraries.html and CodeIgniter custom library error: Call to a member function on a non-object to make this work but I get following error message

A PHP Error was encountered

Severity: Notice

Message: Undefined property: Dataloading::$load

Filename: libraries/dataloading.php

Line Number: 28

What I try is load data for combo boxes from library. here is the code of library class

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 

class Dataloading {

        public function __construct() {

        }

        public function index()
    {

    }

        public function loadcombo(){

        $this->load->model('dataOperateModel');       
        //Calling the getcombo_titel() function to get the arr of titles. Model already loaded.
        $arrStates = $this->dataOperateModel->getcombo_titel();

        //Getting the final array in the form which I will be using for the form helper to create a dropdown.
        foreach ($arrStates as $job_name) {
            $arrFinal[] = $job_name->title;
        }

        $data['job_name'] = $arrFinal;
        $data['main_content']='home/welcome_message';

        //Passing $data to the view, so that we can get the states as an array inside the view.
        $this->load->view('layout',$data);


        }




}

Here is the code of welcome class

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

    class Welcome extends CI_Controller {


            public function __construct() {

                parent::__construct();
                //this condition will check whether user has logged in, otherwise 
                //he will be redirect to login
                if (!$this->session->userdata('logged_in'))
                { 
                     redirect('admin/admin_login');

                }
               // $this->load->model('dataOperateModel');
        }

            public function index()
        {
            //$this->load->view('welcome_message');
                 $this->load->library('dataloading');
                 $this->dataloading->loadcombo();
                 //$this->loadcombo();
        }


    }

can anybody explain where I have done the mistake.

Stack Programmer
  • 679
  • 6
  • 18
kiriappa
  • 822
  • 2
  • 7
  • 14

1 Answers1

1

You need to load Codeigniter instance in order to use Codeigniter core and libraries

$this->ci =& get_instance();

then you can reference as below

$this->ci->load(.....)

and it's better to check how to create your own library

Stack Programmer
  • 679
  • 6
  • 18
Ahmed Gaber
  • 707
  • 1
  • 10
  • 27