joomla 2.5的JTable中的几个表 [英] Several tables in JTable of joomla 2.5
问题描述
我想在MVC组件的JTable
类中的多个表中显示/添加/删除数据:
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);
}
}
构造函数初始化表的ID,以进行删除和编辑.我已经成功显示了三个表的数据,但是当我执行删除操作时,仅删除该表数据,这在JTable
类中是不完整的,但是如果我添加所有表并在JTable
中对其进行初始化,它将给我错误.
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.
推荐答案
Joomla并非以此方式工作.您应该在每个数据库表中使用一个表文件.
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');
那么您可以:
$tableCode->load($id);
或
$tableHotelinfo->delete($id);
等;
但是,您不必为所有这些烦恼,而是为什么不给组件创建者试试?
But instead of messing about with all of this, why don't you give the component creator a try?
这篇关于joomla 2.5的JTable中的几个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!