Getting joomla users name saved to a database with model

ramakunga 24 Mar, 2016
I have a form that saves data under a model named Main. I am trying to store the user who is submitting the form in the attached database. I am using the recommended method to pull the user details from the joomla database into the form array which is fine. The data is stored as shown in debugger output below

Array
(
[user_id] => 63
[name] => David xxxx
[Main] => Array
(
[id] => 28
[uniq_id] => 4304c8655bf95ddff70ee679ca74fd860fd4a9c0
[TimeSheet_id] =>
[user_id] => 63
[name] =>
[created] => 2016-03-24 08:43:40
[modified] => 2016-03-24 11:29:02
[JobClass] =>
[UserEmail] =>
[ApproverEmail] =>

However I want the name to be stored under [Main][name]

How do achieve this ??
GreyHead 24 Mar, 2016
Hi ramakunga,

As a general rule of database management you want to avoid duplicated data so having the User ID saved should be enough as you can always look up the user name from that (and it may have been changed since you saved the record).

If you still want it then you can amend the code a little
<?php
$user = \JFactory::getUser();
$form->data['Main']['name] = $user->name;
?>

Bob
This topic is locked and no more replies can be posted.