问题描述
我需要在 CodeIgniter 中检查用户是否已登录.
I need to check if the user is logged in or not in CodeIgniter.
登录正在 Joomla 站点中进行.
The login is happening in Joomla site.
我尝试了以下方法来初始化 joomla.
I tried the following to initialize joomla .
define( '_JEXEC', 1 );
define( 'DS', DIRECTORY_SEPARATOR );
define('JPATH_BASE', dirname(__FILE__) );
require_once ("../includes/defines.php");
require_once ("../includes/framework.php");
$mainframe =& JFactory::getApplication("site");
$mainframe->initialise();
$session =& JFactory::getSession();
$user = $session->get( 'user' );
但我收到了这条消息:
未找到配置文件,也没有可用的安装代码.退出...
No configuration file found and no installation code available. Exiting...
Joomla 安装在 root 上,codeigniter 安装在 root/advanced 上
Joomla is installed on root and codeigniter on root/advanced
我正在调用控制器中的代码.
I am calling the code in controller.
我该如何解决这个问题?
How can I solve this?
现在我收到此错误:
遇到 PHP 错误
严重性:注意
消息:未定义变量:BM
Message: Undefined variable: BM
文件名:core/CodeIgniter.php
Filename: core/CodeIgniter.php
行号:364
编辑
我的控制器看起来像这样
My Controller look like this
function is_logged()
{
define( '_JEXEC', 1 );
define( 'JPATH_BASE', '../');
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
//require_once ("../libraries/joomla/user/authentication.php");
$mainframe =& JFactory::getApplication("site");
$mainframe->initialise();
$session =& JFactory::getSession();
$user = $session->get( 'user' );
}
目录结构
--Public_html
--Joomla Istallation files
--Advanced [This is a folder ,i installed codeignitor on this folder]
所以 joomla 的路径是 site.com/
而 Codeignitor 的路径是 site.com/advanced
So the path to joomla is site.com/
and path to Codeignitor is site.com/advanced
关于错误的更多信息
Codeignitor Core 上的第 364 行说:
Line 364 on Codeignitor Core says that :
// Mark a benchmark end point
$BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end');
并且我可以在 CI 核心启动时看到以下内容
and i can see the following on the starting of CI core
$BM =& load_class('Benchmark', 'core');
$BM->mark('total_execution_time_start');
$BM->mark('loading_time:_base_classes_start');
推荐答案
我知道这是一篇旧帖子,但您需要确保 JPATH_BASE 指向您的 configuration.php 文件所在的目录.我会使用绝对路径而不是相对路径.
I know its an old post but you need to make sure JPATH_BASE points to the directory where your configuration.php file is. I would use the absolute path rather than a relative path.
这篇关于在 php 中访问 joomla 会话 - codeigniter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!