Ajax and Ajax Frameworks

I have been a developer for nearly 20 years and a web developer for about 10 years. Over the years, I have considered creating a blog to share the things I have learned (and am learning) about web design and development, but I never seemed to have the time. When I began learning about web development using Ajax and Ajax Frameworks, I decided to take the time to create this blog.

My intention for this blog is to focus primarily on Ajax Frameworks, but since web development requires knowledge of many technologies, I will occasionally write about things such as CSS, Javascript, PHP, MySQL, Flash, etc.

Lately, I have been using JQuery as my primary Ajax tool. Although I have used other Ajax Frameworks in the past (Dojo Toolkit, Yahoo! User Interface Library, Scriptaculous/Prototype), JQuery has thus far been the easiest to learn. In my first few posts I will discuss some of the JQuery Plugins that I have created. Some of these include: a plugin for Google Maps (jquery.imGoogleMaps), Form validation and submission  (jquery.imValidateForm), Page Populater (jquery.imPagePopulate), and a plugin to create lists (jquery.imList).

While I am still learning about some of the other Ajax Frameworks, I hope that what I have learned will be helpful to others. Just remember, “When you can pull the pebbles from my hand…”

Posts Tagged ‘Codeigniter’

The demo portion of my site was built using CodeIgniter. I have been working on adding some Flash/AS3 Class demos, so I had to figure out the best way to display the swf files. It was easier than I thought.

Read the rest of this entry »

I finally found time to add my imRichEditor widget (a Dojo widget that integrates TinyMCE) to my demo site. I built my demo site using CodeIgniter and I had to figure out the best way to integrate/call the Dojo files.

Read the rest of this entry »

One aspect of CodeIgniter that I don’t like is the amount of view files that I have to create. Although I create folders to group relevant views, I’m always searching through files to find the view that I need. To reduce the amount of files that I need for a project, I usually create a single view file to handle both inserts and updates to a table. But I had to create a CodeIgniter Helper function in order to make it work.

Read the rest of this entry »

I’m updating a project that I created using CodeIgniter. I have to add a combobox (select) to a registration form that contains state names. I did not want to create a static combo box, so I created a states table in the MySQL database that I’m using for the project. The states table contains three fields (state_id, state_abbrev, state_name).

Read the rest of this entry »

I’m updating a project for a client that I developed using CodeIgniter. One of the updates involves adding a text editor. I decided to use TinyMCE. Integrating TinyMCE with CodeIgniter was easier than I thought.

Create a folder under the js folder and name it tiny_mce (/js/tiny_mce). Download TinyMCE and place the files in the tiny_mce folder.

Read the rest of this entry »

I just completed a website where the client uses PayPal to handle the payment transaction. I have used PayPal quite a bit in the past, but I have always had problems using IPN (Instant Payment Notification). Because of the problems, I usually opted not to use IPN, but I was determined to use it for this project. The primary problem with testing IPN is, because the transaction occurs in the background, it is difficult to figure out where the point of failure is. But that is all behind me now.

Read the rest of this entry »

Using JQuery with CodeIgniter is simple. In fact, using most Ajax frameworks with CodeIgniter is easy. I created a simple JQuery plugin that displays randomly selected images (imBannerRotater).

First I use CodeIgniter’s ‘base_url’ function to link the necessary Javascript files in a main view of my application:

<script type="text/javascript" src="js/jquery/jquery-1.3.1.min.js"></script>
<script type="text/javascript" src="js/jquery/jquery.imBannerRotater-0.5.js"></script>

Next, I define a Javascript variable to be used with by the plugin:

<script type="text/javascript">
//<![CDATA[
base_url = '<?= base_url();?>';
//]]>
</script>

I then use this variable in my JQuery Plugin:

?View Code JASVASCRIPT
$(document).ready(function(){
     $(".randPic").imBannerRotater({
	data_url: base_url + 'assets/sidebar/sidebar.php',
	base_path: base_url + 'assets/sidebar/'
     });
});

That’s about it. While this is a simple example, using CodeIgniter’s base_url function is the key to using JQuery or any other Ajax Framework.

I just finished a project using CodeIgniter. I ftp’d the files to the host provider’s servers. When I attempted to view the website, I received a ‘500 Internal Server Error’. Viewing the error logs, I found: SoftException in Application.cpp:252: File “/home/arrowcol/public_html/index.php” is writeable by group. I looked at the permissions of the index.php file and found that it was set to 0666, so I changed it to 0755 and the site is now up and running.

I recently ran into a problem using CodeIgniter where I kept receiving the error: “Call to a member function on a non-object”. This problem occurred when I was trying to use a method from one model from within another model.

I have a model named mGalleryImages. Within this model, I have a method named addGalleryImages. Within this method, I load another model and tried to call a method from the loaded model:

function addGalleryImages(){
     ...
     $this->load->model('mUtilImages');
     ...
     $this->mUtilImages->setImageFile($_FILES['uploadFile']);
}

I receive the error when the setImageFile method is called. The problem is that when the model sees “$this”, it is looking for a method within the mGalleryImages model. The solution was to use a CodeIgniter function named get_instance().

function addGalleryImages(){
     ...
     $CI =& get_instance();
     $this->load->model('mUtilImages');
     ...
     $CI->mUtilImages->setImageFile($_FILES['uploadFile']);
}

Easy enough, but I would never have thought that this was the problem. I played with this code for hours, trying to figure out why it didn’t work similarly to a regular PHP class. But now I know.

I often need to know the id of the last inserted record into a table. In the past, I’ve used a PHP function:

function getLastInserted($table, $id) {
	$query = "SELECT $id as maxID from $table where $id = LAST_INSERT_ID()";
	$result = $this-&gt;runQuery($query);
	$row = mysql_fetch_row($result);
	return $row[0];
 }

To duplicate this using CodeIgniter’s Active Record, I could write:

function getLastInserted($table, $id) {
	$this->db->select_max($id);
	$Q = $this->db->get($table);
	$row = $Q->row_array();
	return $row[$id];
 }

But, I learned that there is an even faster way that uses one of CodeIgniter’s Helper functions. Immediately after a record has been inserted into the database, I simply call:

$id = $this->db->insert_id();

Although, I am not sure how CodeIgniter knows which field is the primary key, it seems to work.