Here is what I am try'n to do. I'm not sure which parts of the code I mite need to copy here, so let me start with some oversimplified pseudo-code to get going.
I have a main component (com_main) with model, Table, etc all working. From my view.html I can call
$modelTU = $this->getModel('TimeUnits');
$modelTU->GetSchedule($date,...);
The TU Model
public function GetSchedule($date,...){
$query = self::getQuery();
$items = $this->_getList((string) $query...);
if (empty($items)){ //if non found, create new from template
$templateModel = $this->getModel('Templates');
$templateModel->createFromTemplate($date); //create TU's from a tempalte
}
return $items;
}
The Template Model ... public function createFromTemplate($date,...){
//****THIS fails (or =FALSE) if called from module
//This works fine when called from the component!!
$modelTU = JModelLegacy::getInstance('TimeUnit', COM_MODEL_PREFIX); //THIS FAILS
$query = self::getQueryTempalte(....);
$items = $this->_getList((string) $query...);
foreach ($items as $item){
$valTimeUnit = array(
'duration' => $item->duration,
'price' => $item->price
...
);
$modelTU->save($valTimeUnit);
//I also tried store bind here
$tblTu = $modelTU->getTable();
$tblTu->bind(valTimeUnit); //table = False !!!
}
}
I don't know how else to explain this. The bottom line: I load timeunits (TU) ... and if for the given date non exist, I call a template model to load a set of template units to be cloned into TU's
This works fine when called from within the component
If I import the models via in to the module require_once( JPATH_ROOT . '/components/com_main/models/timeunit.php'); etc
it works, I can LOAD Timeunits if they exist just find
It also calls the templateModel to clone new once until I my marker **** The final TimeUnit Model ->Save, or ->getTable(); fails
But only when called from the module
What Am I doing wrong / violating any rules? Namespace imports I don't understand how It can load and work the first two model levels, and then fail to load the last one. I already figured I can't use 'JPATH_COMPONENT_SITE' to require files within my component if I want them to work from my module, I use 'JPATH_ROOT . '/components/com_byteitbooking/'.
Any pointers what I mite miss?
Thanks
EDIT: additional code I made this test, in my timeunit model extending JModelAdmin
public function getTable($type = self::THIS_CLASS_NAME, $prefix = COM_TABLE_PREFIX, $config = array()) {
dumpMessage("-> admin.MODEL.TimeUnit.getTable()");
dumpMessage("-> $type,$prefix");
dump($config,'$config');
$tb = JTable::getInstance($type, $prefix, $config);
dump($tb,'$tb');
return $tb;
//return JTable::getInstance($type, $prefix, $config);
}
results 1st called from component, 2nd from module ...the vars are resolved correctly
- admin.MODEL.TimeUnit.getTable()
- TimeUnit,ByteitBookingTable
- [array] $config = (empty)
- [ByteitBookingTableTimeUnit object] $tb
VS
- admin.MODEL.TimeUnit.getTable()
- TimeUnit,ByteitBookingTable
- [array] $config = (empty)
- [boolean] $tb = FALSE
Do I have to copy the models/tables into the module in order to use them? Is there some kind of restriction in Joomla I am missing?
COM_MODEL_PREFIX
is this constant defined by your component?