外部脚本中的 Joomla 核心函数
最近我正在开发自定义 Joomla 组件。我需要一些外部脚本中的 Joomla 核心功能(不属于 Joomla 框架的一部分)。
假设我有组件及其自定义类,它们不属于 Joomla 结构的一部分。
www.url.com/components/com_customcomp/custom_classes/some_class.php
因此,我将 Joomla 类加载到其中:
if (!defined('JPATH_COMPONENT') or !constant('JPATH_COMPONENT')){
define( '_JEXEC', 1 ); //let direct access
define( 'JPATH', $_SERVER['DOCUMENT_ROOT']);
define( 'JPATH_BASE', $_SERVER['DOCUMENT_ROOT'] . '/administrator' );
define( 'DS', DIRECTORY_SEPARATOR );
define('JPATH_COMPONENT', JPATH_BASE.DS.'components'.DS.'com_customcomp');
//load joomla framework
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php');
require_once( JPATH_LIBRARIES .DS.'joomla'.DS.'factory.php');
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();
}
除了一些 Joomla 核心函数(例如 JURI::root(); )之外,一切正常。它返回:
www.url.com/components/com_customcomp/custom_classes
而不是:
www.url.com/
还有一些奇怪的结果给出 JRoute::_() 等。
问题是什么?如何使该功能正常工作?
我们将不胜感激您的帮助。
recently Im working on custom Joomla component. And I need Joomla core functions in some external scripts(that are not part of Joomla framework).
Let's say I have component and its custom class, that are not part of Joomla structure.
www.url.com/components/com_customcomp/custom_classes/some_class.php
So, I load Joomla classes into it:
if (!defined('JPATH_COMPONENT') or !constant('JPATH_COMPONENT')){
define( '_JEXEC', 1 ); //let direct access
define( 'JPATH', $_SERVER['DOCUMENT_ROOT']);
define( 'JPATH_BASE', $_SERVER['DOCUMENT_ROOT'] . '/administrator' );
define( 'DS', DIRECTORY_SEPARATOR );
define('JPATH_COMPONENT', JPATH_BASE.DS.'components'.DS.'com_customcomp');
//load joomla framework
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php');
require_once( JPATH_LIBRARIES .DS.'joomla'.DS.'factory.php');
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();
}
Everything works fine except some Joomla core functions, like JURI::root(); which returns:
www.url.com/components/com_customcomp/custom_classes
Instead of:
www.url.com/
Also some strange results give JRoute::_() and etc.
What is the problem ? How to make that functions to work properly ?
Your help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我之前遇到过类似的问题...我正在为 Joomla 创建替代入口点。
本机类使用默认值,在“解决”时会给出不好的结果...
唯一的方法是创建一个新的 具有正确 uri 的 JURI 对象。
I had similar problem before... I was creating alternative entry point for Joomla.
The native classes use default values that give bad results when "worked around"...
The only way around it is to create a new JURI object with correct uri.