New module to call username when in session

Have a programming question regarding your component, plug-in, extension or core hacks? Have an interesting tidbit, FAQ or programming tip you’d like to share? This is the place for you.

Moderators: tjay, seadap, Rogue4ngel, matthewhayashida

Post Reply
epifanio67
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Thu Dec 13, 2007 9:09 pm

New module to call username when in session

Post by epifanio67 » Sat Mar 01, 2008 12:17 pm

Hey all,

I am trying to write a module that call/displays the username when in session (after login). The xml file is correct, I am able to install it successfully; but it will not display the username when in session. Please note, I am learning; so my apologies for the question:

mod_yourname.php

defined( '_JEXEC' ) or die( 'Restricted access' );

require_once (dirname(__FILE__).DS.'helper.php');

$yourname = hola::nombre();

require( JModuleHelper::getLayoutPath( 'mod_yourname' ) );


helper.php

class hola {
function nombre() {
$clientInfo =& JApplicationHelper::getClientInfo();
}
}

tmpl/default.php

echo $yourname


Also, both index.html have the basic HTML suggested in the tutorials.


In advanced, thank you for all your help


Regards,

GMassi
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Fri Jun 23, 2006 1:45 pm

Re: New module to call username when in session

Post by GMassi » Tue Mar 04, 2008 12:19 am

Hi,

JApplicationHelper::getClientInfo() doesn't seem the right function for what you want to do. Try

Code: Select all

class hola {
function nombre() {
$user =& JFactory::getUser();
return $user->get('username');
}
}

epifanio67
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Thu Dec 13, 2007 9:09 pm

Re: ->get('varname')

Post by epifanio67 » Tue Mar 04, 2008 2:20 am

Thank you GMassi,

I appreciate the help. It did work.
Since, I am learning; please allow me to ask this basic question:
/*
here: $user is the var, JFactory the class, and getUser() the method avail in the class.
*/
$user =& JFactory::getUser();

/*
then: 'return' returns the var
*/
return $user->get('username');

What I do not understand is the "->get('username')".
I tried "->getUser('username')" to use the method available from class before and it did not work.
Also, I just searched "->get" in php.net and did not return any info.
My question (very basic) what is ->get?
Is it statement?
how do I search for more of these basic terminology? (so I do not go crazy troubleshooting every Class and Method)
:)

My apologies for the stupid question. I just really want to learn.....

Regards,

GMassi
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Fri Jun 23, 2006 1:45 pm

Re: New module to call username when in session

Post by GMassi » Wed Mar 05, 2008 12:15 pm

-> is used to access an object variable or call an object method. Check out PHP official documentation.
Classes and objects


Post Reply