I'm writing a Joomla plug-in that accesses the data stored in a self-written component.
How can I access the code of that component? I'm especially interested in the tables and models.
Is there an official way for doing that?
I'm writing a Joomla plug-in that accesses the data stored in a self-written component.
How can I access the code of that component? I'm especially interested in the tables and models.
Is there an official way for doing that?
Getting models is pretty easy. Just include the model in the plug-in code and create object. It is better to handle all table manipulation in the model, but there are way to load table in the plug-in itself.
Here is how you load the model from plug-in:
<?php
// Path to component
$componentPath = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'mycomponent';
// Include model
require_once $componentPath . DS . 'models' . DS . 'example.php';
// You need to specify table_path because by default model uses
// JPATH_COMPONENT_ADMINISTRATOR . DS . 'tables'
// and you will not have correct JPATH_COMPONENT_ADMINISTRATOR in the plu-in
// unless you specify it in config array and pass it to constructor
$config = array(
'table_path' => $componentPath . DS . 'tables'
);
// Create instance
$model = new MycomponentModelExample($config);
?>
Here is how you load the table from plug-in:
<?php
// 1. Add the path so getInstance know where to find the table
$tablePath = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'mycomponent' . DS . 'tables';
JTable::addIncludePath($tablePath);
// 2. Create instance of the table
$tbl = JTable::getInstance('tableName', 'Table');
?>