weixin_33711641 2018-02-15 18:24 采纳率: 0%
浏览 16

在Ajax PHP中使用joomla API

When i send ajax to some *.php file i cant use joomla api into it. How can i use it? Tried to insert this

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');

But get: failed to open stream: No such file or directory in /siteurl/libraries/php/adduser.php

$.ajax({
    type: 'POST',
    url: '/libraries/php/adduser.php',
    data:,
    success: function(result) { 
        console.log(result);
    },
    error: function(jqxhr, status, exception) {
        console.log(exception);
    }
})
  • 写回答

2条回答 默认 最新

  • weixin_33744141 2018-02-16 14:39
    关注

    $mainframe was the way we invoked the core in mambo if I remember correctly, pardon my memory it must have been 2006. Judging from the DS separator, I think you're at best following a guide from Joomla 1.5.

    Bootstrapping Joomla is well explained in any of the /cli files: the simplest is garbagecron, this is the relevant part, simply adjust your paths:

    <?php
    /**
     * @package    Joomla.Cli
     */
    
    const _JEXEC = 1;
    
    if (file_exists(dirname(__DIR__) . '/defines.php'))
    {
        require_once dirname(__DIR__) . '/defines.php';
    }
    
    if (!defined('_JDEFINES'))
    {
        define('JPATH_BASE', dirname(__DIR__));
        require_once JPATH_BASE . '/includes/defines.php';
    }
    
    require_once JPATH_LIBRARIES . '/import.legacy.php';
    require_once JPATH_LIBRARIES . '/cms.php';
    
    class GarbageCron extends JApplicationCli
    {
        public function doExecute()
        {
            // your code here
        }
    }
    
    JApplicationCli::getInstance('GarbageCron')->execute();
    
    评论

报告相同问题?