我有一個類通知。
但是,這根本不起作用。 公共函數deleteNotification。將無法在96線上工作。 我已經擁有。公共功能,公共靜態功能和靜態功能。 但他們都沒有工作。
誰能看到我的幫助。謝謝! 對不起我的英文不好
<?php
class Notification {
/**
* Config
*
* @access private
*/
private static $config;
/**
* Database
*
* @access private
*/
private $db;
/**
* Session
*
* @access private
*/
private $session;
/**
* Constructor
*
* @access public
*/
public function __construct() {
self::$config = config_load('notification');
$this->db = new Database();
$this->session = new Session();
}
var $type;
var $to_user;
var $from_user;
var $reference;
var $timestamp;
var $newcount;
/**
* getAllNotifications
*
* @access public
*/
public function getAllNotifications() {
$this->newcount = Notification::newCount($this->to_user);
foreach ($this->db->query("SELECT * FROM " .
self::$config['table_notification'] .
" WHERE to_user = 1 ORDER BY `timestamp` DESC LIMIT 10") as $row) {
$result[] = array(
'id' =>$row['id'],
'to_user' =>$row['to_user'],
'from_user' =>$row['from_user'],
'reference' =>$row['reference'],
'type' =>$row['type'],
'seen' =>$row['seen'],
'timestamp' =>$row['timestamp']
);
}
if ($result) {
return $result;
}
return false; //none found
}
/**
* Get newCount
*
* @access public
*/
public function newCount($user) {
$row = ceil($this->db->row_count("SELECT * FROM " .
self::$config['table_notification'] . " WHERE to_user = 1 AND seen = 0 "));
return $row;
}
/**
* deleteNotification
*
* @access public
*/
public static function deleteNotification($id) {
$where = array(
'id' => $id
);
$this->db->where($where);
$this->db->delete(self::$config['table_notification']);
}
}
?>
$id
在這個文件中定義:
update_notifications.php:
<?php
include("common.php");
$id = 1;
$action = $_REQUEST['action'];
switch($action) {
case "seen":
if (isset($_REQUEST['notifications'])) {
$notifications = json_decode($_REQUEST['notifications']);
foreach ($notifications as $notification) {
if (is_numeric($notification)) Notification::Seen($notification);
}
}
break;
case "delete":
$notification = $_REQUEST['notification'];
if (is_numeric($notification)) Notification::deleteNotification($notification);
break;
}
?>
在這個文件我已經設置在第3行$id = 1;
,看看它是否工作。 worldofjr的選項也不起作用。這給出了以下erorr到:
Catchable fatal error: Argument 2 passed to Notification::deleteNotification() must be an instance of Notification, none given, called in C:\Users\Anthony\Desktop\server\htdocs\update_notifications.php on line 17 and defined in C:\Users\Anthony\Desktop\server\htdocs\libraries\Notification.php on line 103
你如何實例化類並調用函數? – jdog 2014-10-04 02:57:01
在調用函數後是否有任何錯誤? – 2014-10-04 02:58:06