Search code examples
joomla

How can I get Joomla component parameter values?


===

UPDATE:

I think now I am literally just trying to get a database value into my component php files, but again, there seems to be very little documentation that can give an example of a function that will return this info like there is in Wordpress.

So I have a table called membersarea_countries that will have records of differnt countries I want to store values for.

I've read about JTable and other things, but how can I simply just bring back the records from this table?

$row = JTable::getInstance('membersarea_countries', 'Table', array());

But this returns a boolean of 0.

I'd really appreciate some help if anyone can.

===

I've been following what several online guides explain, which are all pretty much the same thing, but I never seem to return the values that I'm expecting.

In Components > Members Area (my component), I have a table set up to allow me to enter a record for each country, and then store a uniqueRef, signature, and URL within that record. (for GeoIP purposes).

I've created the first record, however when I try to use the following code, which the tutorials suggest, I don't see any of my fields within this:

$app = JFactory::getApplication();
$params = $app->getParams();
$uniqueRef = $params->get('uniquereference');
$signature = $params->get('signature');

This is all I see in NetBeans: enter image description here

There's nothing about $app, and no sign of the fields I've got in the Joomla backend.

I don't understand what's happening, or exactly what I should be doing here. Wordpress uses a simple get_option function. Can anyone try and help me?


Solution

  • Below is the link to the detailed document about JTable -

    https://docs.joomla.org/Using_the_JTable_class

    Firstly you need to create JTable instance using below code and also change table file name to membersareacountries.php

    JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_membersarea/tables');
    $row = JTable::getInstance('Membersareacountries', 'Table', array());
    

    JTable Class in this file /administrator/components/com_membersarea/tables/membersareacountries.php-

    <?php
    
    defined('_JEXEC') or die();
    
    class TableMembersareacountries extends JTable
    {
        public function __construct($db)
        {
            parent::__construct( '#__membersarea_countrie', 'id', $db );
        }
    }
    

    Then you can use load method to get any records. This accepts primary key value of that table -

    $id = 1;//change id as per your record
    $row->load($id);
    
    //read data
    echo $row->id;
    echo $row->title;