-3

可能重复:
“PHP 通知:未定义的属性”</a>

我尝试在我的 CI 网络中使用外部库。我参考这些链接 https://www.codeigniter.com/user_guide/general/creating_libraries.htmlCodeIgniter 自定义库错误:调用非对象上的成员函数以使其工作,但我收到以下错误消息

A PHP Error was encountered

Severity: Notice

Message: Undefined property: Dataloading::$load

Filename: libraries/dataloading.php

Line Number: 28

我尝试的是从库中加载组合框的数据。这是库类的代码

<?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);


        }




}

这是欢迎类的代码

<?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();
        }


    }

谁能解释我在哪里做错了。

4

1 回答 1

1

您需要加载 Codeigniter 实例才能使用 Codeigniter 核心和库

$this->ci =& get_instance();

那么你可以参考如下

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

最好检查一下如何创建自己的库

于 2012-12-26T10:19:20.537 回答