API:getLoginUserID
From MODx Wiki
$context can be either 'web' or 'mgr'. Returns nothing if the user is not logged in.
API Function Definition:
getLoginUserID
- Versions
- > 0.9.2 ?
- Return Values
- Success: Logged-In User's ID
- Fail: null
- Data Type
- mixed
- Object Hierarchy
- DocumentParser
mixed getLoginUserID();
Determines if user is logged in, be it via Manager Interface, or Web Interface, and returns the ID (int) of the current user. If no user is logged in, null is returned.
[edit]
Examples
[edit]
Related Functions
[edit]
Function Source
| File: | manager/includes/document.parser.class.inc.php |
|---|---|
| Line: | 2015 |
function getLoginUserID($context= '') { if ($context && isset ($_SESSION[$context . 'Validated'])) { return $_SESSION[$context . 'InternalKey']; } elseif ($this->isFrontend() && isset ($_SESSION['webValidated'])) { return $_SESSION['webInternalKey']; } elseif ($this->isBackend() && isset ($_SESSION['mgrValidated'])) { return $_SESSION['mgrInternalKey']; } }
[edit]
Example
// In the front end, returns an array of the logged in user's attributes. $userInfo = $modx->db->getRow( $modx->db->select( "*", $modx->db->getFullTableName('web_user_attributes'), "`internalKey`=".$modx->getLoginUserID() ) );
[edit]
Notes
In the manager, the value returned will be the manager user's ID.
