簡體   English   中英

如何在joomla api / plugin中訪問getdbo?

[英]How to access getdbo in joomla api/plugin?

我正在joomla中創建Web服務/ api,以供移動應用程序訪問。

當我嘗試使用...創建數據庫對象時

$db = &JFactory::getDbo();

我收到錯誤消息..

Fatal error: Call to undefined method ClassName::getDBO() in <Path> on line 108

我的查詢是

我們可以在plugin / api中訪問joomla庫函數或數據庫函數嗎?

如果是,如何?

如果沒有,為什么?

是的,您可以從外部訪問庫和數據庫函數,但需要首先導入相關部分。

//init Joomla Framework
define( '_JEXEC', 1 );
define( 'DS', DIRECTORY_SEPARATOR );
define( 'JPATH_BASE', realpath(dirname(__FILE__).DS.'..'.DS.'..'.DS.'..'));

require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );

$mainframe = JFactory::getApplication('site');

應該做得很好。 然后打電話

//DBQuery
$database =& JFactory::getDBO();

然后從那里走!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM