我尝试在CI网站中使用外部库。我推荐这些链接 https://www.codeigniter.com/user_guide/general/creating_libraries.html 和CodeIgniter custom library error: Call to a member function on a non-object使这项工作 但我收到以下错误消息
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();
}
}
任何人都可以解释我在哪里犯了错误。
答案 0 :(得分:1)
您需要加载Codeigniter实例才能使用Codeigniter核心和库
$this->ci =& get_instance();
然后你可以参考如下
$this->ci->load(.....)