dousha1873 2014-02-12 06:43
浏览 53
已采纳

从外部php脚本访问Joomla

I wrote a component for Joomla 2.5 which uses jquery in the admin part. The js-script calles a helper php file (addrow.php), which returnes a new row for a table using Joomla's form fields. Because that file is outside of the Joomla framework I used these lines to make it work:

define( '_JEXEC', 1 );
define( 'JPATH_BASE', realpath(dirname(__FILE__).'/../..' )); 

require_once( JPATH_BASE.'includes/defines.php' );
require_once( JPATH_BASE.'includes/framework.php' );
require_once( JPATH_BASE.'libraries/joomla/factory.php' );

After the upgrade to Joomla 3.2, this didn't work anymore, I just got

Error displaying the error page: Application Instantiation Error

but by adding

$mainframe = JFactory::getApplication('site');
$mainframe->initialise();

it works again.

My question is, if this is in general the proper way to write external php-scripts for jquery?
And is getApplication('site') correct even if it's for admin?

  • 写回答

1条回答 默认 最新

  • dongxi6897 2014-02-12 07:35
    关注
    1. No — read this answer and this on "Using Joomla Ajax Interface"

    2. Yes, it's an acceptable form (although JFactory::getApplication() will default to the current entry point i.e. site or administrator.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?