Several tables in JTable of joomla 2.5

眉间皱痕 提交于 2019-12-06 11:52:11

问题


I want to display/add/delete data from several table in MVC component, in JTable class:

class HelloWorldTableHelloWorld extends JTable
{
    function __construct(&$db)
    {
        parent::__construct('code', 'id', $db);
      //parent::__construct('#__fairinfo', 'flight_id', $db);
      //parent::__construct('hotelinfo', 'hotelid', $db);
    }
}

Constructor initializes the id's of tables for deletion and edition purpose. I have successfully displayed the data of three tables, but when I performed the deletion operation then only that table data is delete, which is initailized in JTable class, but if I add all tables and initialize them in JTable it gives me an error.


回答1:


Joomla is not designed to work that way. You are meant to use one table file per database table.

In your model you can instantiate all three tables if needed, but each table file should be separate.

In your model do the following:

 $tableCode = JTable::getInstance('Code', 'HelloWorldTable');
 $tableFairinfo = JTable::getInstance('Fairinfo', 'HelloWorldTable');
 $tableHotelinfo = JTable::getInstance('Hotelinfo', 'HelloWorldTable');

Then you can:

 $tableCode->load($id);

or

 $tableHotelinfo->delete($id); 

etc;

But instead of messing about with all of this, why don't you give the component creator a try?



来源:https://stackoverflow.com/questions/12299319/several-tables-in-jtable-of-joomla-2-5

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!