JFactory::getUser with username - Joomla! Forum - community, help and support
hello,
newbie here.
joomla! 2.5.8 - platform 11.4.0
php 5.4.8
i trying access user's information based on username. using following user object.
per joomla! docs-
my code above not user's information.
by examining getuser() code in factory.php, string parameters, execution gets
per operators comparison docs on php.net,
an example indicates
the code comparing (0 != 'angrybird") , evaluate false. believe true evaluation required continue 'username' converted user's 'id' via user.php (getinstance()) , helper.php (getuserid()).
am interpreting correctly or missing something?
newbie here.
joomla! 2.5.8 - platform 11.4.0
php 5.4.8
i trying access user's information based on username. using following user object.
code: select all
$getuser = jfactory::getuser('angrybird');per joomla! docs-
if string passed interpreted user name , converted integer id automatically.
my code above not user's information.
by examining getuser() code in factory.php, string parameters, execution gets
.if ($current->id != $id)
code: select all
public static function getuser($id = null)
{
if (is_null($id))
{
$instance = self::getsession()->get('user');
if (!($instance instanceof juser))
{
$instance = juser::getinstance();
}
}
else
{
$current = self::getsession()->get('user');
if ($current->id != $id)
{
$instance = juser::getinstance($id);
}
else
{
$instance = self::getsession()->get('user');
}
}
return $instance;
}per operators comparison docs on php.net,
if compare number string or comparison involves numerical strings, each string converted number , comparison performed numerically.
an example indicates
(0 != "a") should evaluate false.var_dump(0 == "a"); // 0 == 0 -> true
the code
code: select all
if ($current->id != $id)code: select all
$instance = juser::getinstance($id);am interpreting correctly or missing something?
check out juser class, __construct method.
http://joomlacode.org/gf/project/joomla/scmsvn/?action=browse&path=/development/tags/1.6.x/1.6.3/libraries/joomla/user/user.php&view=markup
the accepted parameter $identifier used load user data object, or if default value of 0 create blank user object. since jfactory merely pattern allowing static calls needed functionality, has same limitations underlying juser class. can check out doc on jfactory v1.6 class here.
http://docs.joomla.org/jfactory/1.6
if you, write dedicated static mehtod in component or module helper class handle logic of taking user name , returning user id. make alter code below, assuming extension component:
http://joomlacode.org/gf/project/joomla/scmsvn/?action=browse&path=/development/tags/1.6.x/1.6.3/libraries/joomla/user/user.php&view=markup
the accepted parameter $identifier used load user data object, or if default value of 0 create blank user object. since jfactory merely pattern allowing static calls needed functionality, has same limitations underlying juser class. can check out doc on jfactory v1.6 class here.
http://docs.joomla.org/jfactory/1.6
if you, write dedicated static mehtod in component or module helper class handle logic of taking user name , returning user id. make alter code below, assuming extension component:
code: select all
jloader::register('myextensionhelper', jpath_component.'/helpers/myextension.php');
$getuser = jfactory::getuser(myextensionhelper::getuseridfromname($name));
Comments
Post a Comment