我有一个PHP类,它定义了检索用户信息和数据的基本函数,我正在尝试使用gravatar函数,但它一直在抛出这个错误,
Fatal error: Call to undefined method User::get_gravatar() in /home/bronypla/public_html/beta/cms_pages/user/profile.php on line 20
这是 profile.php
的代码<?php
get_header();
$args = $_SESSION['PAGE_ARGS'];
$selected_username = $args[0];
if(!does_user_exist($selected_username)):
?>
<div class="site-wrap">
<div class="container text-center">
<p class="alert alert-danger"><strong>Whoops!</strong> That user doesn't exist or couldn't be found, I did find a Luna though!</p>
<img src="<?php echo get_website(); ?>/imgs/luna_happy.png" style="width: auto; max-height: 50%;" />
</div>
</div>
<?php
else:
$selected_user = new User($selected_username);
?>
<div class="site-wrap">
<div class="site-content container">
<div class="page-header">
<div class="thumbnail">
<img src="<?php echo $selected_user->get_gravatar(); ?>">
</div>
<h1><?php echo $selected_username; ?></h1>
</div>
</div>
</div>
<?php
endif;
get_footer();
?>
这是 user.inc.php
的代码<?php
require_once('functions.inc.php');
class User
{
private $username;
function __construct($username) {
$this->username = $username;
}
public function get_username() {
return $this->username;
}
public function get_property($name, $table = "Users")
{
$database = new Database();
$database->open_connection();
$result = mysqli_fetch_array($database->query("SELECT `$name` FROM `$table` WHERE `Username`='$this->username'"));
$database->close_connection();
if(!$database->get_error())
$_SESSION['error'] = base64_encode($database->get_error());
return $result[$name];
}
public function set_property($name, $value, $table = "Users")
{
$database = new Database();
$database->open_connection();
if(mysqli_num_rows($database->query("SHOW COLUMNS FROM `$table` LIKE '$name'")) === 0)
$database->query("ALTER TABLE `Users` ADD $name VARCHAR( 1024 )");
$database->query("UPDATE `$table` SET `$name`='$value' WHERE `Username`='$this->username'");
if(!$database->get_error())
$_SESSION['error'] = base64_encode($database->get_error());
$database->close_connection();
}
public function get_gravatar($s = 250, $d = 'mm', $r = 'pg', $img = false, $atts = array() )
{
$email = $this->get_property('Email');
$url = 'http://www.gravatar.com/avatar/';
$url .= md5( strtolower( trim( $email ) ) );
$url .= "?s=$s&d=$d&r=$r";
if ( $img ) {
$url = '<img src="' . $url . '"';
foreach ( $atts as $key => $val )
$url .= ' ' . $key . '="' . $val . '"';
$url .= ' />';
}
return $url;
}
public static function current_user()
{
$hash = $_COOKIE['cmslogin-hash'];
if(empty($hash))
return FALSE;
$database = new Database();
$database->open_connection();
$result = mysqli_fetch_array($database->query("SELECT `Username` FROM `Users_Login` WHERE `Hash`='$hash'"));
if(!$database->get_error())
$_SESSION['error'] = base64_encode($database->get_error());
if(!$result)
return false;
return new User($result['Username']);
}
}
?>
我似乎无法在这里找到问题,但很可能是一些我很想念的东西,而且看不到它。
感谢您的帮助,
Liam Haworth。