Load Joomla 3.x Framework and Modules in external PHP file(在外部 PHP 文件中加载 Joomla 3.x 框架和模块)
问题描述
我正在将我的 Joomla 2.5 站点迁移到 Joomla 3.3.
I am migrating my Joomla 2.5 site to Joomla 3.3.
现在我正在努力加载 joomla 框架并在 phpbb 模板中显示一个模块.使用以下代码在 Joomla 2.5 中加载 Joomla 框架工作正常:
Now I'm struggling with loading the joomla framework and displaying a module in a phpbb-Template. Loading the Joomla framework worked fine in Joomla 2.5 with this code:
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 在安全选项中启用.
But I doesn't work in Joomla 3.x now. The page stopps loading where this code is. Using PHP in phpbb template files is enabled in the Security options.
有谁知道如何在外部文件中加载joomla 3.x框架?
Does anyone know how to load the joomla 3.x framework in external files?
推荐答案
以下内容非常适合我:
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 根目录相对于外部文件的位置更改 ../.
Try changing this line which you currently have to a relative path as shown above. You may been to change ../ according to where you have your Joomla root in relation to your external file.
define('JPATH_BASE', '/var/customers/webs/tf2swiss/joomlasite');
要测试它是否有效,只需使用以下内容:
To test if it's working, simply use something like this:
var_dump($app);
如果您看到数据显示,则您已成功导入框架
If you see data being shown, then your have successfully imported the framework
这篇关于在外部 PHP 文件中加载 Joomla 3.x 框架和模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在外部 PHP 文件中加载 Joomla 3.x 框架和模块
基础教程推荐
- PHP 类:全局变量作为类中的属性 2021-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何替换eregi() 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
