我在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;
}
}
?>
然后,在一个controller(application/controllers/certificate.php
)方法中,添加了这两行代码:
public function save1()
{
//..... some more code before
$this->load->library('VarMatrixSpecanimal');
$numerical_values = $this->varmatrixspecanimal->get_matrix();
//..... some more code after
但是,当我调用save1方法时,出现此错误:
遇到PHP错误
严重性:通知
消息:未定义的属性:Certificate :: $ varmatrixspecanimal
文件名:controllers / certificate.php
行号:139
我不明白我在哪里做错了,请帮助我。我也检查了CodeIgniter帮助http://www.codeigniter.com/user_guide/general/creating_libraries.html,但我无法得到我的错误
在VarMatrixSpecanimal.php中的构造函数中添加get_instance()函数
public function __construct()
{
$this->variabiliMatrix =& get_instance();
}
在控制器上加载此负载库之后
$this->load->library('varmatrixspecanimal');
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句