我想从用户名中获取Joomla用户ID,我将在外部脚本中使用它。
答案 0 :(得分:2)
如果你不想通过Joomla获取它,只需使用这样的SQL语句:
SELECT id FROM #__users WHERE username = 'someusername';
或者加载Joomla并使用类似这样的代码:
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);