×
Please submit new Bug Reports on GitHub: github.com/Jensen-Technologies/component-creator-issues/issues
UserID default in XML
Gary Hurdman
Fresh Boarder
Posts: 6
2 Jahre 4 Monate her #9974
von Gary Hurdman
UserID default in XML wurde erstellt von Gary Hurdman
Hi I want to store the current Joomla userId in a field (joomlaid) I realise the below is wrong but how would you do this with the component creator or via editing the XML?
<field name="joomlaid"
filter="safehtml"
type="text"
label="COM_BCC_MACCS_FORM_LBL_MACCSTRADER_JOOMLAID"
description="COM_BCC_MACCS_FORM_DESC_MACCSTRADER_JOOMLAID"
hint="COM_BCC_MACCS_FORM_LBL_MACCSTRADER_JOOMLAID"
value="$user->get( 'id' )"/>
Regards - Paul
<field name="joomlaid"
filter="safehtml"
type="text"
label="COM_BCC_MACCS_FORM_LBL_MACCSTRADER_JOOMLAID"
description="COM_BCC_MACCS_FORM_DESC_MACCSTRADER_JOOMLAID"
hint="COM_BCC_MACCS_FORM_LBL_MACCSTRADER_JOOMLAID"
value="$user->get( 'id' )"/>
Regards - Paul
Bitte Anmelden oder Registrieren um der Konversation beizutreten.
Howard H. Taylor
Fresh Boarder
Posts: 2
1 Jahr 1 Monat her - 1 Jahr 1 Monat her #10229
von Howard H. Taylor
Howard H. Taylor antwortete auf UserID default in XML
In your component's XML file (typically yourcomponent.xml), create a custom field type to fetch the Joomla user ID dynamically.
Here's an example of what your field definition might look like:
<field
name="joomlaid"
type="custom"
label="COM_YOURCOMPONENT_FORM_LBL_JOOMLAID"
description="COM_YOURCOMPONENT_FORM_DESC_JOOMLAID"
required="true"
class="YourComponentFieldJoomlaID"
/>
Create a custom PHP script for your field type. In your component's PHP folder, you can add a file like fields/joomlaid.php: MyCCPay Portal
<?php
defined('_JEXEC') or die;
JFormHelper::loadFieldClass('custom');
class JFormFieldJoomlaID extends JFormFieldCustom
{
protected $type = 'JoomlaID';
public function getInput()
{
// Get the current Joomla user
$user = JFactory::getUser();
$joomlaID = $user->get('id');
// Create an input field with the Joomla user ID
$html = '<input type="text" name="' . $this->name . '" id="' . $this->id . '" value="' . $joomlaID . '" readonly />';
return $html;
}
}
In your component's PHP folder, create a helper file (e.g., yourcomponent/helper.php) and define the getJoomlaUserID method:
<?php
class YourComponentHelper
{
public static function getJoomlaUserID($element, $value, $node)
{
// Get the current Joomla user
$user = JFactory::getUser();
return $user->get('id');
}
}
Replace YourComponent with your actual component name.
Either of these methods will dynamically fetch and display the current Joomla user ID in the specified field. Choose the one that best suits your component's structure and organization.
Here's an example of what your field definition might look like:
<field
name="joomlaid"
type="custom"
label="COM_YOURCOMPONENT_FORM_LBL_JOOMLAID"
description="COM_YOURCOMPONENT_FORM_DESC_JOOMLAID"
required="true"
class="YourComponentFieldJoomlaID"
/>
Create a custom PHP script for your field type. In your component's PHP folder, you can add a file like fields/joomlaid.php: MyCCPay Portal
<?php
defined('_JEXEC') or die;
JFormHelper::loadFieldClass('custom');
class JFormFieldJoomlaID extends JFormFieldCustom
{
protected $type = 'JoomlaID';
public function getInput()
{
// Get the current Joomla user
$user = JFactory::getUser();
$joomlaID = $user->get('id');
// Create an input field with the Joomla user ID
$html = '<input type="text" name="' . $this->name . '" id="' . $this->id . '" value="' . $joomlaID . '" readonly />';
return $html;
}
}
In your component's PHP folder, create a helper file (e.g., yourcomponent/helper.php) and define the getJoomlaUserID method:
<?php
class YourComponentHelper
{
public static function getJoomlaUserID($element, $value, $node)
{
// Get the current Joomla user
$user = JFactory::getUser();
return $user->get('id');
}
}
Replace YourComponent with your actual component name.
Either of these methods will dynamically fetch and display the current Joomla user ID in the specified field. Choose the one that best suits your component's structure and organization.
Letzte Änderung: 1 Jahr 1 Monat her von Howard H. Taylor.
Bitte Anmelden oder Registrieren um der Konversation beizutreten.
Ladezeit der Seite: 0.053 Sekunden