joomla 4 - how to do J3 JTable::getInstance

926 views
Skip to first unread message

Gaspar Tur

unread,
Mar 25, 2022, 6:55:36 AM3/25/22
to Joomla! General Development
hello, I'm working on a mvc comoponent on Joomla 4.
I need to generate new child items when i genertate the father.

I'm at postsavehook and at joomla 3 I did somethjing like this

foreach ($list_of_childs as $child_id)  {
JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_mycomponent/table');
$child= JTable::getInstance('child ', 'Table', array());

$child->load( $child_id);
....
                

}

but mow getInstance is deprecated and i need to use Factory, but evertithing i've tried do

do finis in a server error or load on bool.


Any ideas?

I know i can do it direct with Factory::getDbo(); and qyeris, but the idea of use bind, store, load, ... etc from table it was great.
Thanks


Владимир Старовойтенко

unread,
Mar 29, 2022, 6:52:18 AM3/29/22
to joomla-de...@googlegroups.com
$table = $this->app->bootComponent('com_mycomponent')->getMVCFactory()
->createTable('Mytable', 'Administrator');
var_dump($table->get('source'));

And example table. Table file must be placed at administrator/component/mycomponent/src/Table/MytableTable.php

namespace Joomla\Component\Mycomponent\Administrator\Table;

defined('_JEXEC') or die;

use Joomla\CMS\Table\Table;

class MytableTable extends Table
{
public $source = 'Test text';
}

пт, 25 мар. 2022 г. в 13:55, Gaspar Tur <gaspa...@gmail.com>:
--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-gene...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/joomla-dev-general/fa30d2f4-2460-44af-be24-7d121a704771n%40googlegroups.com.


--
Have a nice day!
Reply all
Reply to author
Forward
0 new messages