当我尝试访问我的库的功能时遇到此错误: 遇到PHP错误
严重性:注意
消息:未定义属性:ControllerUser :: $ alertClasse
文件名:controllers / ControllerUser.php
行号:183
回溯:
文件: C:\ wamp64 \ WWW \ logistock \应用\控制器\ ControllerUser.php 行:183功能:_error_handler
文件: C:\ wamp64 \ WWW \ logistock \应用\控制器\ ControllerUser.php 行:22函数:call_user_func_array
文件:C:\ wamp64 \ www \ logistock \ index.php行:315功能: require_once
这是我的图书馆:
defined('BASEPATH') OR exit('No direct script access allowed');
class AlertClasse
{
protected $CI;
public function __construct()
{
$this->CI =& get_instance();
$this->CI->load->model('AlerteModel');
}
public function stockSeuil()
{
$query=$this->CI->AlerteModel->getarticles();
$tabStockSeuil = array();
foreach($query as $tab)
{
if($tab->art_solde<=$tab->seuil_alert_art)
{
$article[] = $tab->id_art;
$article[] = $tab->lib_art;
$article[] = $tab->art_solde;
$article[] = $tab->seuil_alert_art;
$article[] = $tab->perissable;
$tabStockSeuil[] = $article;
$article = array();
}
}
return $tabStockSeuil;
}
public function stockExpire()
{
$query=$this->CI->AlerteModel->get_art_lot();
$tabartexpire = array();
$datejour = date('d/m/Y');
$djour = explode("/", $datejour);
$auj = mktime(00, 00, 00,$djour["1"],$djour["0"],$djour["2"]);
foreach($query as $tab)
{
if($tab->date_expir!=0)
{
$datexpiration= $tab->date_expir;
if ($auj>=$datexpiration)
{
$id = $tab->id_lot;
$artexpire[] = $tab->lib_art;
$artexpire[] = $tab->qte_lot;
$artexpire[] = $tab->date_enregistrement;
$artexpire[] = $tab->date_expir;
$tabartexpire[] =$artexpire;
$this->articles_model->mis_au_rebut($id);
$artexpire = array();
}
}
}
return $tabartexpire;
}
public function ExpireProche()
{
$query=$this->CI->AlerteModel->get_art_lot();
$tabartexpire = array();
$datejour = date('d/m/Y');
$djour = explode("/", $datejour);
$auj = mktime(00, 00, 00, $djour["1"], $djour["0"], $djour["2"]);
$nextDat =time() + (5 * 24 * 60 * 60);
$temp =date('d/m/Y', $nextDat);
$temp = explode("/", $temp);
$nextDate = mktime(00, 00, 00, $temp["1"],$temp["0"],$temp["2"]);
foreach($query as $tab)
{
if($tab->date_expir!=0)
{
$datexpiration= $tab->date_expir;
if (intval($auj)<intval($datexpiration) && intval($nextDate) >=
intval($datexpiration))
{
$artexpire[] = $tab->lib_art;
$artexpire[] = $tab->qte_lot;
$artexpire[] = $tab->date_enregistrement;
$artexpire[] = $tab->date_expir;
// On met ensuite le résultat obtenu dans un tableau
$tabartexpire[] =$artexpire;
$artexpire = array();
}
}
}
return $tabartexpire;
}
}
并在我的控制器中:
defined('BASEPATH') OR exit('No direct script access allowed');
class ControllerUser extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->library('alertClasse');
$this->load->database();
$this->load->library('session');
}
}
这里我尝试访问该方法:
public function affichageUser(){
//error here
$tabExpirProch = $this->alertClasse->ExpireProche();
$priv = $this->UserModel->getpriv();
$this->load->view('users/listUser',['privilege'=>$priv]);
}
答案 0 :(得分:0)
发生此错误是因为codeigniter无法在您的应用程序/库文件夹中找到该文件。
确保您图书馆课程的文件名为“AlertClasse.php” 因为codeigniter声明了以下创建库的规则:
- 文件名必须大写。例如:Myclass.php
- 类声明必须大写。例如:class Myclass
- 班级名称和文件名必须匹配。
醇>
https://www.codeigniter.com/userguide3/general/creating_libraries.html#storage
答案 1 :(得分:0)
您必须使用类的名称访问库的方法:
$tabExpirProch = $this->AlertClasse->ExpireProche();
答案 2 :(得分:0)
我的proyect也有同样的问题。 我可以通过这种方式调用每个模型,在CI v3.1.6上
模型(仅显示差异):
class SomeClass extends CI_Model{
function __construct(){
parent::__construct()
}
function someFunction($foo){
//do something
}
}
在控制器中:
class SomeController extends CI_Controller{
function __construct(){
parent::__construct();
//Load model, no problem
$this->load->model('SomeClass');
//Load library, no problem
$this->load->library('MyLibrary');
}
function someFunctionToUseModelFunction(){
$foo = 'Hello my friend';
//no problem with using the model
$bar = $this->SomeClass->SomeFunction($foo);
//library, NOT FOUND
$a = $this->MyLibrary->someFunctionInLibrary();
}
}
当我尝试使用库时,当我无法调用库中的函数时,我无法检查名称,文件名,我在哪里调用那些......没有。 (抱歉我的英文)我“小写”了图书馆的名字,我做了这个
function __construct(){
$this->load->library('MyLibrary');
}
function functionToCallTheLbrary(){
//this way it has worked for my so far with all the libraries i have
//lowercase the class name, and call the functions with the names u declare those
$var = $this->mylibrary->someFunction();
}
希望我的回答能帮到你。