【问题标题】:Load Joomla 3.x Framework and Modules in external PHP file在外部 PHP 文件中加载 Joomla 3.x 框架和模块
【发布时间】:2019-04-10 04:19:11
【问题描述】:

我正在将我的 Joomla 2.5 网站迁移到 Joomla 3.3。

现在我正在努力加载 joomla 框架并在 phpbb 模板中显示一个模块。 使用以下代码在 Joomla 2.5 中加载 Joomla 框架可以正常工作:

define( '_JEXEC', 1 );
define('JPATH_BASE', '/var/customers/webs/tf2swiss/joomlasite');
define( 'DS', DIRECTORY_SEPARATOR );
require_once('../configuration.php');
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
require_once ( JPATH_BASE .DS.'libraries'.DS.'joomla'.DS.'factory.php' );
require( JPATH_LIBRARIES. '/import.php');
// Joomla! library imports
jimport( 'joomla.environment.uri' );
jimport( 'joomla.user.user');
jimport('joomla.application.module.helper');

/* Create the Application */
$mainframe =& JFactory::getApplication('site');
jimport('joomla.plugin.helper');

但我现在不能在 Joomla 3.x 中工作。页面停止加载此代码所在的位置。 在安全选项中启用在 phpbb 模板文件中使用 PHP。

有谁知道如何在外部文件中加载 joomla 3.x 框架?

【问题讨论】:

  • 如果有人发现这实际上是在寻找如何加载 Joomla 1.5(是的,即使在 2017 年也使用过,尤其是在 dermert 中)...:docs.joomla.org/…

标签: php joomla joomla3.0 phpbb phpbb3


【解决方案1】:

以下内容非常适合我:

define('_JEXEC', 1);
define('JPATH_BASE', '../');
require_once JPATH_BASE . 'includes/defines.php';
require_once JPATH_BASE . 'includes/framework.php';

// Create the Application
$app = JFactory::getApplication('site');

尝试将您当前拥有的这一行更改为如上所示的相对路径。您可能已经根据您的 Joomla 根目录相对于外部文件的位置来更改 ../

define('JPATH_BASE', '/var/customers/webs/tf2swiss/joomlasite');

要测试它是否工作,只需使用以下内容:

var_dump($app);

如果您看到显示的数据,则说明您已成功导入框架

【讨论】:

  • 感谢您的回复。这适用于 php 文件,但不适用于我的 phpBB 模板overall_header.html。该网站在$app = JFactory::getApplication('site') 处停止加载
  • 没关系,phpBB 有时很烦人。当我将此代码包含为外部 php 文件 <!-- INCLUDEPHP somefile.php --> 时,它似乎有效。还是谢谢
  • 我用过这个——define('JPATH_BASE', realpath(dirname(FILE)));而不是定义('JPATH_BASE', '../');
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-01
  • 2013-10-31
  • 2018-05-23
  • 2012-02-22
  • 1970-01-01
相关资源
最近更新 更多