I would like to get the Joomla user Id from the user name, I will be using this in an external script.
if you don't want to get it via Joomla, just use a SQL statement like this:
SELECT id FROM #__users WHERE username = 'someusername';
Or load Joomla and use something like this code:
if (!defined('_JEXEC')) {
define( '_JEXEC', 1 );
define ('JPATH_BASE', "c:\\wamp\\www\\oursite");
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
require_once ( JPATH_BASE .DS.'libraries'.DS.'joomla'.DS.'factory.php' );
require_once ( JPATH_LIBRARIES.DS.'joomla'.DS.'import.php'); // Joomla library imports.
$app=& JFactory::getApplication('site');
}
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('id');
$query->from($db->quoteName('#__users'));
$query->where($db->quoteName('username')." = ".$db->quote('someusername'));
$db->setQuery($query);
$user_id = $db->loadResult();
// Get a JUser object, if you want/need it
$user = JFactory::getUser($user_id);
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加