[eluser]salman@lee[/eluser]
<?php
class chat extends CI_controller
{
function chat()
{
parent::__construct();
$this->load->model('chat_model');
}
function index()
{
$this->view_data['chat_id'] = 1;
if(! $this->session->userdata('logged_in')) {
redirect('user/login');
}
$this->view_data['user_id'] = $this->session->userdata('user_id');
$this->view_data['page_title'] = 'chatting a web base chat app';
$this->view_data['page_content'] = 'view_chat';
$this->load_view('view_main', $this->view_data);
function ajax_add_chat_message()
{
/*thing that need to be past'ed to this function
*
*
*chat_id
*user_id
*chat_message_content
*
*
*
*
*/
$chat_id=$this->input->post('chat_id');
$user_id=$this->input->post('user_id');
$chat_message_contant=$this->input->post('chat_id', TRUE);
$this->chat_model->add_chat_message_content($chat_id, $user_id, $chat_message_content);
}
function ajax_get_chat_message()
{
$chat_id = $this->input->post('chat_id');
$chat_message = $this->chat_model->get_chat_message('$chat_id');
if ($chat_messages->num_rows()> 0)
//we have some chat let's return it
$chat_messages_html = '<ul>';
foreach ($chat_messages->result() as $chat_message)
$chat_messages_html .= '<li>' . $chat_message->chat_messge_content . '</li>';
}
$chat_messages_html .= '</ul>';
$result = array('status' => 'ok', 'content' => $chat_messages_html);
echo json_encode($result);
exit();
}
//else
/* {
$result = array('status' => 'ok', 'content' => '');
echo json_encode($result);
exit();
}
*/
}
?>