Skip to content

Codeigniter Tutorial – Creating A Web Chat App – Final Word

by alboyd on June 7th, 2011

Hi Everyone!

There have been a few votes on the poll for whether I should post a 6th video in the series. The result was pretty much that Yes I should however I have had a look at the things that I wanted to tell you about to finish off the series and I don’t think they warrant a video.

In a nutshell here are the things I was going to mention:

In the chat controller functions that are called through our AJAX requests it might be worth adding the following line to the start of each of those functions:


if (! $this->input->is_ajax_request())
{
exit();
}

This will prevent anyone from loading the function unless from an AJAX request. I’m not sure if there is any good reason to do this for this app but it’s probably a good idea to get in the practice of checking this.

For the chat you will notice once you have lots of chat in the chat_viewport that you have to always scroll down to see the last message. You could make the following change to have it automatically scroll for you.

Change this line (used in 2 places):


$("div#chat_viewport").html(current_content + data.content);

To:


$("div#chat_viewport").html(current_content + data.content).animate({ scrollTop: $("div#chat_viewport").attr("scrollHeight") }, 1000);

Source Code: Here is the source code for where we finished up if anyone is interested.

From → General Posts

Comments are closed.