Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7184815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:16:44+00:00 2026-05-28T18:16:44+00:00

I’m making a Social Networking Website using this book called PHP5 Social Networking. I’m

  • 0

I’m making a Social Networking Website using this book called PHP5 Social Networking.
I’m trying to edit the profile but I get this error

Fatal error: Call to a member function getObject() on a non-object which is referring to this following line;

if ( $registry->getObject('authenticate')->isLoggedIn() 
 && ( $registry->getObject('authenticate')->getUser()->getUserID() == $this->id 
   || $registry->getObject('authenticate')->getUser()->isAdmin() == true ) )

I’m a newbie to PHP so any help would be appreciated greatly.

This is the entire file;

<?php

/**
 * Profile model
 */
class Profile{

    /**
     * The registry
     */
    private $registry;

    /**
     * Profile ID
     */
    private $id;

    /**
     * Fields which can be saved by the save() method
     */
    private $savable_profile_fields = array( 'name', 'hometown', 'university', 'gender', 'photo', 'bio', 'dob' );

    /**
     * Users ID
     */
    private $user_id;

    /**
     * Users name
     */
    private $name;

    /**
     * Users hometown
     */
    private $hometown;

    /**
     * Users University 
     */
    private $university;

    /**
     * Users genders
     */
    private $gender;

    /**
     * Users bio
     */
    private $bio;

    /**
     * Users dob
     */
    private $dob;

    /**
     * Users photograph
     */
    private $photo;

    private $valid;

    /**
     * Profile constructor
     * @param Registry $registry the registry
     * @param int $id the profile ID
     * @return void
     */
    public function __construct( Registry $registry, $id=0 )
    {
        $this->registry = $registry;
        if( $id != 0 )
        {
            $this->id = $id;
            // if an ID is passed, populate based off that
            $sql = "SELECT * FROM profile WHERE user_id=" . $this->id;
            $this->registry->getObject('db')->executeQuery( $sql );
            if( $this->registry->getObject('db')->numRows() == 1 )
            {
                $this->valid = true;

                $data = $this->registry->getObject('db')->getRows();
                // populate our fields
                foreach( $data as $key => $value )
                {
                    $this->$key = $value;
                }
            }
            else
            {
                $this->valid = false;
            }

        }
        else
        {
            $this->valid = false;
        }
    }

    /**
     * Is the profile valid
     * @return bool
     */
    public function isValid()
    {
        return $this->valid;
    }

    /**
     * Sets the users name
     * @param String $name
     * @return void
     */
    public function setName( $name )
    {
        $this->name = $name;
    }


    /** 
    * Sets the users university 
    $@param String $university 
    */
    public function setUniversity( $university )
    {
        $this->university = $university;

    }


    /**
     * Set the users date of birth
     * @param String $dob the date of birth
     * @param boolean $formatted - indicates if the controller has formatted the dob, or if we need to do it here
     */
    public function setDOB( $dob, $formatted=true )
    {
        if( $formatted == true )
        {
            $this->dob = $dob;
        }
        else
        {
            $temp = explode('/', $dob );
            $this->dob = $temp[2].'-'.$temp[1].'-'.$temp[0];
        }
    }

    /**
     * Sets the hometown of users
     * @param String $hometown
     * return void
     */
    public function setHometown( $hometown )
    {
        $this->hometown = $hometown;
    }

    /**
     * Set the gender of the user
     * @param String $gender the gender
     * @param boolean $checked - indicates if the controller has validated the gender, or if we need to do it
     * @return void
     */
    public function setGender( $gender, $checked=true )
    {
        if( $checked == true )
        {
            $this->gender = $gender;
        }
        else
        {
            $genders = array();
            if( in_array( $gender, $genders ) )
            {
                $this->gender = $gender;
            }
        }
    }

    /**
     * Sets the users bio
     * @param String bio
     * @return void
     */
    public function setBio( $bio )
    {
        $this->bio = $bio;
    }

    /**
     * Sets the users profile picture
     * @param String photo name
     * @return void
     */
    public function setPhoto( $photo )
    {
        $this->photo = $photo;
    }

    /**
     * Save the user profile
     * @return bool
     */
    public function save()
    {
        // handle the updating of a profile
        if( $registry->getObject('authenticate')->isLoggedIn() && ( $registry->getObject('authenticate')->getUser()->getUserID() ==  $this->id || $registry->getObject('authenticate')->getUser()->isAdmin() == true  ) )


        {
            // we are either the user whose profile this is, or we are the administrator
            $changes = array();
            foreach( $this->saveable_profile_fields as $field )
            {
                $changes[ $field ] = $this->$field;
            }
            $this->registry->getObject('db')->updateRecords( 'profile', $changes, 'user_id=' . $this->id );
            if( $this->registry->getObject('db')->affectedRows() == 1 )
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        else
        {
            return false;
        }
    }

    /**
     * Convert the users profile data to template tags
     * @param String $prefix prefix for the template tags
     * @return void
     */
    public function toTags( $prefix='' )
    {
        foreach( $this as $field => $data )
        {
            if( ! is_object( $data ) && ! is_array( $data ) )
            {
                $this->registry->getObject('template')->getPage()->addTag( $prefix.$field, $data );
            }
        }
    }



    /**
     * Return the users data
     * @return array
     */
    public function toArray( $prefix='' )
    {
        $r = array();
        foreach( $this as $field => $data )
        {
            if( ! is_object( $data ) && ! is_array( $data ) )
            {
                $r[ $field ] = $data;
            }
        }
        return $r;
    }

    /**
     * Get the users name
     * @return String
     */
    public function getName()
    {
        return $this->name;
    }


    /**
     * Get the users photograph
     * @return String
     */
    public function getPhoto()
    {
        return $this->photo;
    }

    /**
     * Get the users ID
     * @return int
     */
    public function getID()
    {
        return $this->user_id;
    }

}


?>

It also needs to pass through;
profileinformationcontroller.php

<?php

/**
 * Profile information controller
 */
class Profileinformationcontroller {

    /**
     * Constructor
     * @param Registry $registry
     * @param int $user the user id
     * @return void
     */
    public function __construct( $registry, $directCall=true, $user )
    {
        $this->registry = $registry;
        $urlBits = $this->registry->getObject('url')->getURLBits();
        if( isset( $urlBits[3] ) )
        {
            switch( $urlBits[3] )
            {
                case 'edit':
                    $this->editProfile();
                    break;
                default:
                    $this->viewProfile( $user );
                    break;
            }   
        }
        else
        {
            $this->viewProfile( $user );
        }

    }

    /**
     * View a users profile information 
     * @param int $user the user id
     * @return void
     */
    private function viewProfile( $user )
    {
        // load the template
        $this->registry->getObject('template')->buildFromTemplates( 'header.tpl.php', 'profile/information/view.tpl.php', 'footer.tpl.php' );
        // get all the profile information, and send it to the template
        require_once( FRAMEWORK_PATH . 'models/profile.php' );
        $profile = new Profile( $this->registry, $user );
        $profile->toTags( 'p_' ); 
    }

/**
 * Edit your profile
 * @return void
 */
private function editProfile()
{
    if( $this->registry->getObject('authenticate')->isLoggedIn() == true )
    {
        $user = $this->registry->getObject('authenticate')->getUser()->getUserID();
        if( isset( $_POST ) && count( $_POST ) > 0 )
        {
                    require_once( FRAMEWORK_PATH . 'models/profile.php' );

            // edit form submitted
            $profile = new Profile( $this->registry, $user );
            $profile->setName( $this->registry->getObject('db')->sanitizeData( $_POST['name'] ) );
            $profile->setHometown( $this->registry->getObject('db')->sanitizeData( $_POST['hometown'] ) );
            $profile->setUniversity( $this->registry->getObject('db')->sanitizeData( $_POST['university'] ) );
            $profile->setGender( $this->registry->getObject('db')->sanitizeData( $_POST['gender'] ), false );
            $profile->setBio( $this->registry->getObject('db')->sanitizeData( $_POST['bio'] ) );
            $profile->setDOB( $this->registry->getObject('db')->sanitizeData( $_POST['dob'] ), false );
            if( isset( $_POST['profile_picture'] ) )
            {
                require_once( FRAMEWORK_PATH . 'lib/images/imagemanager.class.php' );
                $im = new Imagemanager();
                $im->loadFromPost( 'profile_picture', $this->registry->getSetting('uploads_path') .'profile/', time() );
                if( $im == true )
                {
                    $im->resizeScaleHeight( 150 );
                    $im->save( $this->registry->getSetting('uploads_path') .'profile/' . $im->getName() );
                    $profile->setPhoto( $im->getName() );
                }
            }
            $profile->save();
            $this->registry->redirectUser( array('profile', 'view', 'edit' ), 'Profile saved', 'The changes to your profile have been saved', false );
        }
        else
        {
            // show the edit form
            $this->registry->getObject('template')->buildFromTemplates( 'header.tpl.php', 'profile/information/edit.tpl.php', 'footer.tpl.php' );
            // get the profile information to pre-populate the form fields
            require_once( FRAMEWORK_PATH . 'models/profile.php' );
            $profile = new Profile( $this->registry, $user );
            $profile->toTags( 'p_' ); 
        }
    }
    else
    {
        $this->registry->errorPage('Please login', 'You need to be logged in to edit your profile');
    }
}

}


?>

Is there anyone who can help???
I’ll send the source code to your email as well if it helps at all?

Thanks in advance 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T18:16:44+00:00Added an answer on May 28, 2026 at 6:16 pm

    You did not reference the object property $registry that you want to access, but an undefined local variable $registry. Change the line to this:

    if( $this->registry->getObject('authenticate')->isLoggedIn() && ( $this->registry->getObject('authenticate')->getUser()->getUserID() ==  $this->id || $this->registry->getObject('authenticate')->getUser()->isAdmin() == true  ) )
    

    …or add this line above your existing one:

    $registry = $this->registry;
    

    I would go for the first option but realistically it makes little/no difference.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.