0

I'm still creating a component for Joomla 2.5 that have 4 forms: one main form (title, description) and others 3 forms with more fields. Main form have an id autoincrement that is the foreign key for other tables.

mainTable -> PK: id
secondTable -> PK: id, FK: idMainTable
thirdTable -> PK: id, FK: idMainTable
fourTable -> PK: id, FK: idMainTable

When I try to retrieve the populate forms, the id passed over the forms is the same of main form (pk of main form).

In view.html.php

function display($tpl = null) 
    {
        // Initialiase variables.
        $this->state    = $this->get('State');
        $this->item     = $this->get('Item');
        $this->mainForm = $this->get('Form');

        // GET OTHER MODELS FOR OTHER FORMS
        $secondMod = JModel::getInstance('second', 'secondModel');
        $this->secondForm = $secondMod->getForm();

        $thirdMod = JModel::getInstance('third', 'thirdModel');
        $this->thirdForm = $thirdMod->getForm();

        $fourMod = JModel::getInstance('four', 'fourModel');
        $this->fourForm = $fourMod->getForm();

        ...

        parent::display($tpl);
    }

All forms are loaded, but the passed id is the same for mainModel, so the forms for the other 3 models are empty.

How can I get the complete form with correct loaded data and the correct relationship?

Thanks

1

SOLVED (maybe...)

In each model, I have override the getItem method like this:

public function getItem($pk = null)
{
        $item = null;

        $idMain = (int) JRequest::getVar('id');

        if ($idMain > 0)
        {
            $db =& JFactory::getDBO();
            $query = $db->getQuery(true);

            $query->select('second.*');
            $query->from('#__secondTable AS s');
            $query->innerJoin('#__firstTable AS f ON s.idFK = f.id');
            $query->where('f.id = '. (int) $idMain);

            $db->setQuery($query);
            $item =  $db->loadObject();
            return $item;
        }
}

But I have many doubts about this statement:

$idMain = (int) JRequest::getVar('id');

$pk is always null...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.