开发者

Joomla core functions in external scripts

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 );
        de开发者_如何学Gofine('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.


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.

$uri = JFactory::getURI('correct uri');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜