I am a new comer to Joomla! as well as a new comer to the component development.

I wish to produce a component which have the ability to outcomes of 2 tables.

joomla v 1.6:

A table's structure:

CREATE TABLE `#__a` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;

B table's structure:

CREATE TABLE `#__b` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;

AB table's structure:

CREATE TABLE `#__ab` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`id_a` int(11) NOT NULL,
`id_b` int(11) NOT NULL,
PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;

Think that we've already produced the fundamental create, edit page and remove action using the MVC for any and B (created from the hello world component). In the hellow world tutorial we're able to know obvious concerning the file and folder structure and also the componet's code, however in the tutorial there's only one table, but here there's 2 tables as well as new id id table.

Therefore it implies that within the component we are developing here, you will find 2 submenus.

Within the edit or new page

  1. There's A particulars block which we are able to fill title.(done in the tutorial)

  2. There's B connecting block which we are able to pick the B (choose option, can choose more then 1) to include in to the A as well as display list the B we added. In each and every item within the list, it features a remove button or connect to unlink between your A and B.

Any ideas how you can do please?

Thanks and Sincerely Buddies,

Rithy

Firstly you take some logic which will save the outcomes within the reference table and also the second part would be to retrieve the information to become proven around the user side. You'll need a Model:

class CompControllerA extends JControllerForm { 
   // Here put your save code
   //....
   function save() {
     $formData = JRequest::getVar('jform');
     $bRecords = $formData['bRecords'];
     $aRecordId = $formData['id'];
     $referenceModel->delete($aRecordId); // Delete all records that has same ID as current record
     foreach($bRecords as $row) {
        $data['id']=0;
        $data['a_id']=$aRecordId;
        $data['b_id']=(int)$row;
        $bModel->save($data);
     }

     // dont forget to call parent method
     parent::save();
   }
}

Next thing happens when you produce the just for go ahead and take is a result of the reference table and show the right leads to the shape.

Here's some example code of the component I have built.

class IbookModelExtra extends JModelAdmin
{
    protected function loadFormData()
    {
        $db =& $this->getDbo();
        $query = $db->getQuery(true);
        $query->select('b_id')->from('#__table_a_b')->where('a_id='.$data->id);
        $db->setQuery((string)$query);
        $data->b = $db->loadResultArray();
    }
}