Customising a component: call a username

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
andrewvanmarle
Joomla! Apprentice
Joomla! Apprentice
Posts: 7
Joined: Fri Jun 08, 2007 3:14 pm

Customising a component: call a username

Post by andrewvanmarle » Wed Feb 13, 2008 11:08 pm

I'm working with Linx a links submission component, which is great but I'd like to modify it slightly:

where it asks you to enter your name in a field, i'd like it to hard code the users (user)name:

This is from the php file and creates the fields to fill stuff in:

$recip_url = mosGetParam( $_REQUEST, 'recip_url', '' );
$new_url = mosGetParam( $_REQUEST, 'new_url', '' );
$new_url_name = mosGetParam( $_REQUEST, 'new_url_name', '' );
$new_url_description = mosGetParam( $_REQUEST, 'new_url_description', '' );
$new_name = mosGetParam( $_REQUEST, 'new_name', '' );
$new_email = mosGetParam( $_REQUEST, 'new_email', '' );
$cat_id = mosGetParam( $_REQUEST, 'cat_id', '' );

I'd like to replace this:
$new_name = mosGetParam( $_REQUEST, 'new_name', '' );
with something that calls the (user)name instead of the field.

I grabbed this from the debug when opening a (community builder) profile page:
7
SELECT id, name, email, block, sendEmail, registerDate, lastvisitDate, activation, params
FROM jos_users
WHERE id = 62

I tried echo statements, but all i got was errors, what should I do?

macbloke
Joomla! Apprentice
Joomla! Apprentice
Posts: 12
Joined: Thu Feb 21, 2008 10:23 am

Re: Customising a component: call a username

Post by macbloke » Sat Feb 23, 2008 10:37 pm

In J!1.0 you need to use:

Code: Select all

global $my;

$userid = $my->id;
$username = $my->username;

In J!1.5 you need to use:

Code: Select all

$user =& JFactory::getUser();

$userid = $user->get('id');
$username = $user->get('username');

Hope this helps.

StuG
Last edited by macbloke on Sun Feb 24, 2008 7:24 pm, edited 1 time in total.

andrewvanmarle
Joomla! Apprentice
Joomla! Apprentice
Posts: 7
Joined: Fri Jun 08, 2007 3:14 pm

Re: Customising a component: call a username

Post by andrewvanmarle » Sun Feb 24, 2008 7:03 pm

Hey stu, thanks for the first step ...

I tried copying that in the php doc...and got an error:

Code: Select all

Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in D:\Website\xampp\htdocs\nedgolfvet\components\com_linx\linx.php on line 203
Guess I should have done something different?

(maybe a touch of back ground will help:
The is the linx component, and hat I want to happen is that instead of a user being asked to fill in a name, it's automatically filled in for him so there is no chance of "fudging")

macbloke
Joomla! Apprentice
Joomla! Apprentice
Posts: 12
Joined: Thu Feb 21, 2008 10:23 am

Re: Customising a component: call a username

Post by macbloke » Sun Feb 24, 2008 7:25 pm

You're missing a ';' from the end of one of the lines. Check you've got them all complete and you should be good to go.

Regards,

StuG

macbloke
Joomla! Apprentice
Joomla! Apprentice
Posts: 12
Joined: Thu Feb 21, 2008 10:23 am

Re: Customising a component: call a username

Post by macbloke » Sun Feb 24, 2008 7:28 pm

If you're copying directly, you might want to use:

Code: Select all

$new_name = $username;
in lieu of your mosGetParam request.

StuG

andrewvanmarle
Joomla! Apprentice
Joomla! Apprentice
Posts: 7
Joined: Fri Jun 08, 2007 3:14 pm

Re: Customising a component: call a username

Post by andrewvanmarle » Sun Feb 24, 2008 11:08 pm

thanks i'll try it at once!


Post Reply