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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog