Some basic MVC component questions

For Joomla! 3.x Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Post Reply
adams1
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 104
Joined: Fri May 12, 2017 7:34 am

Some basic MVC component questions

Post by adams1 » Sun May 12, 2019 5:17 pm

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)?

adams1
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 104
Joined: Fri May 12, 2017 7:34 am

Re: Some basic MVC component questions

Post by adams1 » Sun May 12, 2019 7:24 pm

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!

nickywoolf
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Fri Jul 26, 2019 1:08 pm

Re: Some basic MVC component questions

Post by nickywoolf » Fri Jul 26, 2019 2:05 pm

$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.


Post Reply

Return to “Joomla! 3.x Coding”