나는 내가 그들이에 필요한 컨트롤러에로드되는 다양한 라이브러리를 구축하는 코드 점화 프레임 워크를 사용하여 응용 프로그램을 구축하고로드를 허용하지 않습니다.코드 점화 나 여러 라이브러리
을 나는 시도하고로드 할 때
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;
}
}
}
>
그때는 $ CI를 포함하여 위의 그림과 같이 CI_Controller을 확장하지 않음으로써이 문제를 제압
'subclass_prefix'에 대해'application \ config \ config.php'에 어떤 설정이 있습니까? 기본값은 MY_'이며 라이브러리 파일 이름은 무엇입니까? – Re0sless
이 코드를 사용해보십시오'$ CI = & get_instance(); $ CI-> load-> library ('messaging', $ options) ' –
왜 여러 라이브러리가 문제라고 생각 했습니까? PHP 오류가 훨씬 유익하지 않아야합니까? '/ home/totalcar/public_html/application/controllers/home.php'의 코드 73은 무엇입니까? – xiankai