CodeIgniter Forums
Joomla and Codeigniter - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Joomla and Codeigniter (/showthread.php?tid=39636)



Joomla and Codeigniter - El Forum - 03-16-2011

[eluser]alejandronanez[/eluser]
Hi there, how are you guys.

The thing is that now I'm developing a small web application with CI and later I will integrate it with Joomla in a wrapper. (I have to do this because the client has been working with Joomla from a long time ago)
The thing is that I need to know what user is logged in (the user logs in with joomla) to know what method call with Codeigniter.

Am I clear? Has anyone done this before?

Thanks guys Big Grin


Joomla and Codeigniter - El Forum - 04-03-2011

[eluser]danielgrin[/eluser]
I based my solution on code found here http://forum.joomla.org/viewtopic.php?f=304&t=580193.

At first I tried to load the Joomla framework within a CI library, but this caused a series of errors, and seemed like more trouble than it was worth.

My current working solution is to use CURL to access a custom script. I'm sure this could be refined further but I needed a quick solution.


JOOMLA SIDE (loads Joomla framework and returns logged in user object as JSON)
file: get_joomla_user.php (could be in the site root or anywhere as long as paths are correct)

Code:
<?php
define ( '_JEXEC', 1 );
define ( 'JPATH_BASE', $_SERVER ['DOCUMENT_ROOT'] . '/JOOMLA_ROOT/' );

define ( 'DS', DIRECTORY_SEPARATOR );
require_once (JPATH_BASE . DS . 'includes' . DS . 'defines.php');
require_once (JPATH_BASE . DS . 'includes' . DS . 'framework.php');
$mainframe = & JFactory::getApplication ( 'site' );
$mainframe->initialise ();

//I am using Jomsocal, so these are required to retrieve Jomsocial user object
require_once ( JPATH_ROOT.DS.'components'.DS.'com_community'.DS.'defines.community.php');
require_once (COMMUNITY_COM_PATH.DS.'libraries'.DS.'apps.php' );


//$user = JFactory::getUser (); //Joomla user object
$user = CFactory::getUser (); //Jomsocial user object
if ($user->id == 0) //user is not logged in
{
echo 'false';
} else {
echo json_encode($user); //return the user object as JSON object
}

CI SIDE - fetch user object via file_get_contents
file: CI_APP_FOLDER/libraries/Joomla_user.php

Code:
<?php
if (! defined ( 'BASEPATH' ))
    exit ( 'No direct script access allowed' );

class Joomla_user {
    var $CI; //create CI instance so we can access libraries
    var $get_user_url = 'http://URL_TO_get_joomla_user.php';
    
    function __construct() {
        $this->CI = & get_instance ();
    }    
    function get_user() {
        //Need to set cookie context so that Joomla can access it's session/user cookie
        $opts = array ('http' => array ('header' => 'Cookie: ' . $_SERVER ['HTTP_COOKIE'] . "\r\n" ) );
        $context = stream_context_create ( $opts );
        $juser = json_decode ( file_get_contents ( $this->get_user_url, false, $context ) );        
        if(!$juser){                            
            //Not logged in - echo error -or-
            //redirect to joomla login page
            $this->CI->load->helper('url');
            redirect('JOOMLA_LOGIN_PAGE_URL', 'refresh');
        }else{
            //Logged in
            return $juser;
        }
    }

}

I hope this helps.

Daniel


Joomla and Codeigniter - El Forum - 04-09-2011

[eluser]gowrav vishwakarma[/eluser]
you should see USE CI FOR JOOMLA DEVELOPMENT or
USING CI FOR JOOMLA DEVELOPMENT

post a reply back to developer or forum if have any trouble ..


Joomla and Codeigniter - El Forum - 04-09-2011

[eluser]gowrav vishwakarma[/eluser]
in any of your controller (made in xCIDEveloper) to know the current user logged in use the follwoing line..
Code:
$current_user_id=JFactory::getUser()->id;
Here in xCIdeveloer you can use seamless working of joomla and CI...


Joomla and Codeigniter - El Forum - 04-09-2011

[eluser]danielgrin[/eluser]
My requirements were to bridge an existing CI application with Joomla so that they still functioned independently. Adding CI to work within Joomla components was not an option, although it looks like something I would like to explore in the future.


Joomla and Codeigniter - El Forum - 04-09-2011

[eluser]gowrav vishwakarma[/eluser]
Well I haven't tried it a well but if you are good at CI internals then .. just replace this systems application with your one .. and yes don't forget to look at some config there in..


Joomla and Codeigniter - El Forum - 07-29-2011

[eluser]gowrav vishwakarma[/eluser]
Now Develop for Joomla in CodeIgniter, xCIDeveloper 0.6 released. installs in Joomla 1.5, 1.6 and 1.7 in same way and components developed in xCI works same in any of joomla version. http://www.xavoc.com/