4
A
回答
4
獲取模型非常簡單。只需在插件代碼中包含來自組件的模型PHP文件並根據需要創建對象。
最好處理模型中的所有表操作,但是有方法可以在插件本身中加載表。
這裏是你如何從加載模型插件:
<?php
// Path to component
$componentPath = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'mycomponent';
// Include model
require_once $componentPath . DS . 'models' . DS . 'example.php';
// You need to specify table_path because by default model uses
// JPATH_COMPONENT_ADMINISTRATOR . DS . 'tables'
// and you will not have correct JPATH_COMPONENT_ADMINISTRATOR in the plu-in
// unless you specify it in config array and pass it to constructor
$config = array(
'table_path' => $componentPath . DS . 'tables'
);
// Create instance
$model = new MycomponentModelExample($config);
?>
這裏是你如何從插件加載表:
<?php
// 1. Add the path so getInstance know where to find the table
$tablePath = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'mycomponent' . DS . 'tables';
JTable::addIncludePath($tablePath);
// 2. Create instance of the table
$tbl = JTable::getInstance('tableName', 'Table');
?>
相關問題
- 1. 如何在內容腳本和插件之間共享代碼?
- 2. 如何在組件之間共享ContextMenu
- 3. 在Flex和AIR之間共享代碼
- 4. 在AddViewController和DetailViewController之間共享代碼
- 5. 在NSDocument和UIDocument之間共享代碼
- 6. 在UITableViewCell和UICollectionViewCell之間共享代碼
- 7. 兩個outlook VSTO插件之間的共享代碼
- 8. asmx和wcf之間的共享代碼
- 9. eclipse和intellij之間的共享代碼
- 10. NativeScript:如何在視圖之間共享和動畫組件?
- 11. Angular2在組件之間共享數據
- 12. 在React組件之間共享屬性
- 13. 在Angularjs組件之間共享數據
- 14. 多個站點之間的wordpress共享代碼代碼文件
- 15. 如何在內部和外部模塊之間共享代碼
- 16. 如何在Silverlight和mvc3應用程序之間共享代碼
- 17. 如何在2個項目之間共享WinForms和代碼
- 18. 如何在Interface Builder和代碼之間共享常量?
- 19. 如何在Eclipse和Android Studio之間共享Java源代碼?
- 20. 如何在我的Java代碼和.proto文件之間共享Enum值
- 21. 在iPhone和PC之間共享文件
- 22. 在Python代碼和C++代碼之間共享信息(IPC)
- 23. 在swfs之間共享代碼
- 24. 在項目之間共享代碼庫
- 25. joomla在模塊之間共享變量
- 26. 如何在兩個Eclipse插件之間共享通用功能?
- 27. Spring組件之間的信息共享
- 28. 共享組件moduls之間2
- 29. React組件之間共享變量
- 30. 在Qt項目之間共享代碼文件