我正在使用 Code Igniter 框架构建一个应用程序,在该框架中我构建了许多不同的库,我将这些库加载到需要它们的控制器中。
当我尝试将多个库加载到我的“主”控制器中时,我收到以下消息:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Home::$messaging
Filename: controllers/home.php
Line Number: 73
Fatal error: Call to a member function getMessages() on a non-object in /home/totalcar/public_html/application/controllers/home.php on line 73
我以前从未遇到过这个错误,因为在加载多个库之前我有控制器没问题。似乎认为消息传递库不存在或未加载。我已经确保库的文件名有一个大写的第一个字母,类声明也是如此,这似乎没有任何区别。
我分别加载我的库,如下所示。(请注意,我已从控制器中删除了许多不相关的代码,以便在此处阅读)
public function index() {
...
//Load Helpers
$this->load->helper('menu');
$this->load->helper('layout');
//Load Libraries
$this->load->library('pusher');
$this->load->library('test');
//Load User Details
$data['userid'] = $this->session->userdata('userid');
$data['modules'] = getModules($this->layout_model, $this->socialmedia_model);
//Build Menu
$data['menuItems'] = buildMenu($this->session->userdata('user_group_id'), $this->config);
$data['firstName'] = $this->session->userdata('firstName');
//Unread Messages
$options = array(
'userId' => $data['userid'],
'opened' => 0
);
$this->load->library('messaging', $options);
$data['unreadMessages'] = $this->messaging->getMessages();
$data['mailIcon'] = (empty($data['unreadMessages'])) ? "mailButton.png" : "mailButtonUnread.png";
有人可以在这里提供任何指导吗?谢谢
编辑:这是我的图书馆代码:
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
class Messaging extends CI_Controller {
private $options;
private $unreadMessages;
public $mailIcon;
function __construct($options) {
parent::__construct();
$this->load->model('messaging_model');
$this->load->model('staff_model');
$this->options = $options;
}
function getMessages() {
$unreadMessages = $this->messaging_model->getMessages($this->options);
$this->unreadMessagesReturn = array();
$mailIcon = (empty($unreadMessages)) ? "mailButton.png" : "mailButtonUnread.png";
if(!empty($unreadMessages)) {
foreach($unreadMessages as $message) {
$fromUserDetails = $this->staff_model->getStaffMemberDetails($message['from_id']);
if((isset($fromUserDetails['profile_image_small'])) && $fromUserDetails['profile_image_small'] != "") {
$profileImageSmall = $this->config->base_url() . "images/profileImages/" . $fromUserDetails['profile_image_small'];
} else {
$profileImageSmall = $this->config->base_url() . "images/noImage.png";
}
$name = $fromUserDetails[0]['first_name'] . " " . $fromUserDetails[0]['last_name'];
$dateSent = date('Y-m-d', strtotime($message['time_sent']));
$messageTruncated = substr($message['message'], 0, 70) . "...";
$this->unreadMessagesReturn[] = array(
'fromPic' => $profileImageSmall,
'fromName' => $name,
'subject' => $message['subject'],
'message' => $message['message'],
'messageTruncated' => $messageTruncated,
'dateSent' => $dateSent
);
}
return $this->unreadMessagesReturn;
}
}
}
?>