Php CodeIgniter:加载自定义库时出错

Php CodeIgniter:加载自定义库时出错,php,codeigniter,Php,Codeigniter,我在CodeIgniter中创建了一个自定义库,并将其定位在application/libraries/VarMatrixSpecanimal.php <?php defined('BASEPATH') OR exit('No direct script access allowed'); class VarMatrixSpecanimal { protected $variabiliMatrix; public function __construct() {

我在CodeIgniter中创建了一个自定义库,并将其定位在
application/libraries/VarMatrixSpecanimal.php

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

class VarMatrixSpecanimal {
    protected $variabiliMatrix;

    public function __construct() {
        $variabiliMatrix['cat']['no']=1;
        $variabiliMatrix['dog']['a']=2;
        $variabiliMatrix['bird']['b']=3;
    }

    public function get_matrix() {
        return $this->variabiliMatrix;
    }
}
?>
但是当我调用save1方法时,我得到了以下错误:

遇到PHP错误
严重性:注意
消息:未定义的属性:证书:$varmatrixspecanimal
文件名:controllers/certificate.php
行号:139

我不明白我哪里做错了,请帮帮我。
我还检查了CodeIgniter帮助,但无法获得错误信息

我遇到过类似的情况,因为我忘记了这行代码:
parent::\u构造
在我的u构造或构造函数中。

在VarMatrixSpecanimal.php的构造函数中添加get_instance()函数

public function __construct()
{
    $this->variabiliMatrix =& get_instance();

}
在此之后,在控制器上加载库

$this->load->library('varmatrixspecanimal'); 

在程序顶部添加具有正确路径的包含文件将解决此问题

include "../../VarMatrixSpecanimal.php";

尝试从以下位置更改构造函数:

public function __construct() {
    $variabiliMatrix['cat']['no']=1;
    $variabiliMatrix['dog']['a']=2;
    $variabiliMatrix['bird']['b']=3;
}
为此:

public function __construct() {
    $this->variabiliMatrix['cat']['no']=1;
    $this->variabiliMatrix['dog']['a']=2;
    $this->variabiliMatrix['bird']['b']=3;
}

此外,在加载库时,我认为您不需要大写任何字母

控制器从哪个类扩展?CI_控制器?加载库时,请尝试仅使类的第一个字母大写
Varmatrixspecanimal.php
类Varmatrixspecanimal{}
然后
$this->load->library('Varmatrixspecanimal')在控制器中加载库时,使用库名称的小写字母。像这样..
$this->load->library('varMatrixSpecanimal')但库类名的第一个字母必须是大写。是,我的控制器扩展了CI_Controller@wolfgang1983我以这种方式更改了类定义
class Varmatrixspecanimal{..}
并将文件名重命名为
Varmatrixspecanimal.php

,然后调用
$this->load->library('Varmatrixspecanimal')。。。。。但是我得到了同样的错误对不起,
parent::\uu construct()
public function __construct() {
    $this->variabiliMatrix['cat']['no']=1;
    $this->variabiliMatrix['dog']['a']=2;
    $this->variabiliMatrix['bird']['b']=3;
}