Joomla通过PHP脚本添加文章应用程序实例化错误 [英] Joomla add article via php script Application Instantiation Error

查看:96
本文介绍了Joomla通过PHP脚本添加文章应用程序实例化错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个脚本,以便通过php脚本插入一些文章。此脚本在我的本地计算机(xampp)上运行,但是当我将整个joomla项目部署到Web服务器时,我收到以下错误消息:

i created a script in order to insert some articles via a php script. This script is working on my local machine (xampp), but when i deploy the whole joomla project to my web server i get the following error message:


Error显示错误页面:应用程序实例化错误:应用程序实例化错误

Error displaying the error page: Application Instantiation Error: Application Instantiation Error

通过添加一些回显调用,我能够找到导致错误的行: / p>

By adding some echo calls, i was able to find the line which causes the error:

$app = JFactory::getApplication('site');

现在,我想知道如何解决此问题并使我的功能也可以在Web服务器上运行。

Now i am wondering how to fix this behaviour and make my function also run on the web server.

下面,我将提供系统信息和php函数的开始,直到出现该行为止,这将导致错误消息:

Below i will provide my system informations and the beginning of my php function until the line, which causes the error message:


  • joomla版本:3.6.5稳定

  • db版本:5.6.34-79.1-log

  • php版本:5.6.30-he.0

  • 网络服务器:Apache

  • joomla version: 3.6.5 Stable
  • db version: 5.6.34-79.1-log
  • php version: 5.6.30-he.0
  • web server: Apache
<?php

echo "STARTING;   ";

// get db connection
include('../includes/mysql.inc.php');

// get all sql querys
include('./autoNewsQuerys.inc.php');

/**
 * Prepare joomla framework to insert article correctly
 */
if (!defined('_JEXEC')) {
    define('_JEXEC', 1);
    define('JPATH_BASE','/is/htdocs/wp1088688_4E1H7PYJFK/www');
    require_once(JPATH_BASE . '/includes/defines.php');
    require_once(JPATH_BASE . '/includes/framework.php');
    defined('DS') or define('DS', DIRECTORY_SEPARATOR);
}

echo "searching app;";
$app = JFactory::getApplication('site');
echo "Found app;";

 




完整的浏览器输出



开始;搜索应用程序;显示错误页面时出错:应用程序实例化错误:由于 /is/htdocs/wp1088688_4E1H7PYJFK/www/1500AutoNews/autoNews.php已经发送了标头,因此无法启动会话。在第3行。

STARTING; searching app;Error displaying the error page: Application Instantiation Error: Failed to start the session because headers have already been sent by "/is/htdocs/wp1088688_4E1H7PYJFK/www/1500AutoNews/autoNews.php" at line 3.

因此您可以看到错误是由JFactory调用引起的。

So as you can see the error is caused by the JFactory call. 'Found app' is never printed out.

推荐答案

只需复制Joomla index.php 文件转换为另一个文件,然后将 $ app->执行代码替换为您的代码。

Just copy the Joomla index.php file to another file and then replace the $app->execute code with your code.

注意:您不需要包含任何 MySQL 库-由于正在加载Joomla环境,因此您可以访问JDatabase类,该类是数据库抽象层。

Note: You don't need to include any MySQL library - since you are loading the Joomla environment then you have access to the JDatabase class, which is a database abstraction layer.

另一个说明:此文件 autoNewsQuerys.inc.php 可能包含一些问题(也许您正在尝试实例化应用程序,但尚未加载Joomla环境)。您应该将其移到末尾。

Another note: this file autoNewsQuerys.inc.php likely contains some issues (maybe you are trying to instantiate the app there, but the Joomla environment hasn't loaded yet). You should move it to the end.

这篇关于Joomla通过PHP脚本添加文章应用程序实例化错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆