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();
    
    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?