User

This example demonstrates how to get the current user by both of Legacy style and Cube style.

Legacy style anchor.png

The most simplest way is using the global variable.


 global $xoopsUser;

But, this way is not standard in OOP style. The formal style is the following;


 $root =& XCube_Root::getSingleton();
 $xoopsUser =& $root->mContext->mXoopsUser;

You must pay attention that $xoopsUser does not have to be an object always. If the current access is without login, $xoopsUser is null. This spec is the tradition from XOOPS2. And, it isn't cut out for checking whether the current user is loging.


 $root =& XCube_Root::getSingleton();
 $xoopsUser =& $root->mContext->mXoopsUser;
 if (!is_object($xoopsUser)) {
   ...
 }

Page Top

Cube Style anchor.png


 $root =& XCube_Root::getSingleton();
 $user =& $root->mContext->mUser;

This $user is the principal object which implements specific interfaces that you can check roles. But, in Legacy, the principal object doesn't have profile informations which are nick name, location, hobby and more.

XOOPS Cube layer always offers the principal object through the context object. Therefore, you don't need to check whether the principal object is not null.


Front page   Freeze Diff Backup Copy Rename ReloadPrint View   New Page Page list Search Recent changes   Help   RSS of recent changes (RSS 1.0) RSS of recent changes (RSS 2.0) RSS of recent changes (RSS Atom) Powered by xpWiki
Counter: 15366, today: 2, yesterday: 3
Princeps date: 2007-01-12 (Fri) 03:22:55
Last-modified: 2007-01-16 (Tue) 17:39:20 (JST) (4602d) by Anonymous

Welcome | News | Overview | Documentation | Forum | Tutorialstop
Brasilian | French | German | Greek | Japanese | Korean | Russian | T-Chinese
Powered by XOOPS Cube 2001-2011 The XOOPS Cube Project