Welcome Guest, Not a member yet? Register   Sign In
[SOLVED]Blueimp's AJAX Chat + CodeIgniter integration
#1

(This post was last modified: 08-22-2016, 01:26 AM by dimawebmaker. Edit Reason: Add solution! )

I have a problem with integration Blueimp's AJAX Chat in my project based on CI framework.

In root durectory of my project, I made new folder "chat" and upload inside chat files. After I edit chat /lib/custom.php and write this:

PHP Code:
define('BASEPATH'AJAX_CHAT_PATH.'../system/');
define('APPPATH'AJAX_CHAT_PATH.'../application/');
define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');
define('VIEWPATH'APPPATH.'views/');
require_once 
AJAX_CHAT_PATH.'../system/core/CodeIgniter.php'

When I try to go url: http://myproject.com/chat/ it redirect me on auth page.

After auth, I cant open http://myproject.com/chat/ it keep redirecting me on other controllers of my project. Here is .htaccess

Code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]


So I think after I import this file ../system/core/CodeIgniter.php in chat, it start using route, instead to redirect.

I want open this url http://myproject.com/chat/, but can't coz CI think that it is another controller.

======================================

Solution.

hi hi I solved this problem, long time ago and just now want to write my solution, maybe it will help someone in future Smile

First need change CI index.php
Need make absolute path
PHP Code:
//$system_path = 'system';
$system_path dirname(__FILE__) . DIRECTORY_SEPARATOR 'system';

//$application_folder = 'application';
$application_folder dirname(__FILE__) . DIRECTORY_SEPARATOR 'application'

Now in Chat's custom.php add this code
PHP Code:
ob_start();
require_once 
__DIR__ "/../../index.php";
ob_end_clean();
$CI =& get_instance();
$CI->load->library('session'); 

Now our auth function in CustomAJAXChat.php will be looks like this:
PHP Code:
function getValidLoginUserData() {

        
$CI =& get_instance();
        
$CI->load->library('session');

        
$userData = array();
        
$userData['userID'] = $CI->session->userdata('id');
        
$userData['userName'] = $CI->session->userdata('name');
        if(!
$userData['userID']) {
            return 
header'Location: http://domain.com/user/login'true301 );
        }
        if(
$CI->session->userdata('status') == OR $CI->session->userdata('status') == 2) {
            
$userData['userRole'] = AJAX_CHAT_ADMIN;
        } else {
            
$userData['userRole'] = AJAX_CHAT_OPERATOR;
        }

        return 
$userData;
    } 

All other parts u can write by urself Smile
Reply
#2

Create a Chat controller and run it from there.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB