将变量存储在查询的类中

时间:2013-08-06 00:00:25

标签: php class

我有一个图像类,我想在启动类(登录时)后运行查询,然后在类中store变量profile_picture_thumb .etc或至少通过this访问其他功能。以下操作无效,并将this字段作为空白返回。

class Images
{
    var $main_prepend = 'm_';
    var $thumb_prepend = 't_';
    var $default_ext = 'jpg';
    var $cropfactor;
    private $prepLocation = '';
    private $profile_picture_thumb = '';
    private $profile_picture_large = '';
    private $facebook_id = '';
    public function __construct()
    {
        $sql = Nemesis::select("profile_picture_thumb, profile_picture_large, facebook_id", "users", "id = '{$_SESSION[user_id]}'");
        list($profile_picture_thumb, $profile_picture_large, $facebook_id) = $sql->fetch_row();
        $this->profile_picture_thumb = $profile_picture_thumb;
        $this->profile_picture_large = $profile_picture_large;
        $this->facebook_id = $facebook_id;
        if (local()) {
            $prepLocation = XAMPP;
        } else {
            $prepLocation = '';
        }
    }
    public function profilePic($show = true, $delete = false)
    {
        if ($show) {
            echo '<script type="text/javascript">$(function() { $("#profile-picture").tipsy({fade: true}); });</script>';
            if (is_file(ROOT . $this->profile_picture_thumb)) {
                echo '<img src="' . reduce_double_slashes('../' . $this->profile_picture_thumb) . '" id="profile-picture" class="profile-picture" title="Your Profile Picture">';
            } elseif (!empty($this->facebook_id)) {
                // if there is no profile picture set, and user has listed fb profile picture, get profile picture
                $fb_p_thumb = "http://graph.facebook.com/{$facebook_id}/picture";
                $fb_p_large = "http://graph.facebook.com/{$facebook_id}/picture?type=large";
                echo '<img src="' . $fb_p_thumb . '" id="profile-picture" class="profile-picture" title="Facebook Profile Picture">';
            } else {
                echo '<img src="images/50x50_placeholder.gif" id="profile-picture" class="profile-picture" title="Click to add profile picture">';
            }
        }
        if ($delete) {
            if (is_file(ROOT . $this->profile_picture_thumb) || is_file(ROOT . $this->profile_picture_large)) {
                if (!unlink(ROOT . $this->profile_picture_thumb) && !unlink(ROOT . $this->profile_picture_large)) {
                    $msg->add('e', "Could not delete user profile picture!");
                }
            } else {
                $msg->add('e', "Files not found in directory.");
            }
        }
    }

我也尝试过:

public function __construct()
{
    static $prepLocation = '';
    static $profile_picture_thumb = '';
    static $profile_picture_large = '';
    static $facebook_id = '';

    $sql = Nemesis::select("profile_picture_thumb, profile_picture_large, facebook_id", "users", "id = '{$_SESSION[user_id]}'");
    list($profile_picture_thumb, $profile_picture_large, $facebook_id) = $sql->fetch_row();
    $this->profile_picture_thumb = $profile_picture_thumb;
    $this->profile_picture_large = $profile_picture_large;
    $this->facebook_id = $facebook_id;
    if (local()) {
        $prepLocation = XAMPP;
    } else {
        $prepLocation = '';
    }
}

0 个答案:

没有答案