Page 1 of 1

Some basic MVC component questions

Posted: Sun May 12, 2019 5:17 pm
by adams1
Hi,

I'm examining the Joomla basic MVC component example and have some questions:

In this PHP line:

Code: Select all

JTable::getInstance($type, $prefix, $config); 
What exactly is $type (beside the name of the table)? What is it exactly used for? In the table definition file\class there is also a table name given in the constructor when calling the JTable parrent class constructor.

$prefix means the class prefix, which is in the table definition .php file?

Furthermore:

Code: Select all

$jinput = JFactory::getApplication()->input;
$id     = $jinput->get('id', 1, 'INT');
"->get()" Which kind of input is accessed this way (i.e. $_GET, $_POST, cookies or sg. else)?

Re: Some basic MVC component questions

Posted: Sun May 12, 2019 7:24 pm
by adams1
Addition:

Why "site/views/helloworld/tmpl/default.xml" tells that where the field definition is ("addfieldpath="/administrator/components/com_helloworld/models/fields") when it will be seen on the admin interface of Joomla (in this case of the online basic tutorial)?

Thank you!

Re: Some basic MVC component questions

Posted: Fri Jul 26, 2019 2:05 pm
by nickywoolf
$type is the name of your JTable class.

From com_helloworld:

Code: Select all

class HelloWorldTableHelloWorld extends JTable
{
    // ...
}
$type (name) is HelloWorld
$prefix is HelloWorldTable

When you call JTable::getInstance() it combines $prefix and $type to create the name of your class: "HelloWorldTable" + "HelloWorld"

class JTable

Code: Select all

	public static function getInstance($type, $prefix = 'JTable', $config = array())
	{
		// Sanitize and prepare the table class name.
		$type       = preg_replace('/[^A-Z0-9_\.-]/i', '', $type);
		$tableClass = $prefix . ucfirst($type);
	}
In the constructor you use the name of your database table

Code: Select all

class HelloWorldTableHelloWorld extends JTable
{
	function __construct(&$db)
	{
		parent::__construct('#__helloworld', 'id', $db);
	}
}
---

I think by default $input->get('id', 1, 'INT') gets the value from $_REQUEST.