Integrations: Fatal error: Call to a member function getId()

mr117119

Joined: 2009-12-22
Posts: 1
Posted: Tue, 2009-12-22 11:17

hi,

I have member system,and I want my member logging Automatically,
but when I try myself, these codes Effectively, other member will shown error:

Fatal error: Call to a member function getId() on a non-object in /srv/www/htdocs/new_web/album.php on line 37

could you help me? what can I do?

my code:

$ret = GalleryEmbed::init( array ('g2Uri'=>'/album/main.php', 'embedUri'=>'/album.php', 'fullInit'=>'false'));

if (isset($_GET['username'])){ // if we get a username

$GL_uid=$_GET['username'];

$ret2 = GalleryEmbed::isExternalIdMapped($GL_uid, 'GalleryUser');

if ($ret2 && $ret2->getErrorCode() & ERROR_MISSING_OBJECT) {

//gallery don't have these username
$ret3 = GalleryEmbed::createUser($GL_uid, array('username'=>$GL_uid));

if ($ret3) {

} else {

list($ret, $user) = GalleryCoreApi::fetchUserByUsername($GL_uid);
$g2uid = $user->getId(); // these line will shown Fatal error!!!
$ret2 = GalleryEmbed::addExternalIdMapEntry($GL_uid, $g2uid, 'GalleryUser');
$ret992 =GalleryEmbed::checkActiveUser($GL_uid);
//$ret993 =GalleryEmbed::login($GL_uid);

}

}else{ //gallery already have these username

list($ret, $user) = GalleryCoreApi::fetchUserByUsername($GL_uid);
$g2uid = $user->getId();
$ret2 = GalleryEmbed::addExternalIdMapEntry($GL_uid, $g2uid, 'GalleryUser');
$ret992 =GalleryEmbed::checkActiveUser($GL_uid);
//$ret993 =GalleryEmbed::login($GL_uid);

}

}

$g2data = GalleryEmbed::handleRequest();
if ($g2data['isDone']) {
exit;
}
GalleryEmbed::done();

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Tue, 2009-12-22 12:44

you need to check $ret when you call list($ret, $user) = GalleryCoreApi::fetchUserByUsername($GL_uid);
apparently its failing and you're trying to fetch the id for $user when there was none.

list($ret, $user) = GalleryCoreApi::fetchUserByUsername($GL_uid);
if ($ret){
    there was an error fetching the user lets create one instead
}
$g2uid = $user->getId();

-s
FlashYourWeb and Your Gallery with The E2 XML Media Player for Gallery2