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…”

Archive for the ‘Codeigniter’ Category

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->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.

Share

Before I begin to learn any new language, I generally purchase a book or two. A few months ago, I purchased the book, “Professional CodeIgniter”. This is a really good book in that I could copy/paste/tweak much of the code from the book for an application that I was working on. I learned the basics and then some (integrating Ajax, TinyMCE, etc). I highly recommend it.

Share

I am fairly new to the PHP framework scene. I have been using CodeIgniter for about 3-4 months and I have found it to be quite straightforward.  I have been able to develop websites quickly using an understandable structure.

When I first began defining constants with CodeIgniter, I used a method that I learned in the book, “Professional CodeIgniter
“. I placed all of my constants at the bottom of the config.php file (system/application/config/config.php).

$config['jquery_assets'] = 'assets/js/jquery/';

To access the configuration item in my application, I would write something like:

$this->plugin = base_url() . $this->config->item('jquery_assets') .'imgooglemaps/jquery.imGoogleMaps-0.5.js';

While this works fine, I really wanted to define constants in the traditional PHP way. I recently noticed a file named constants.php (system/application/config/constants.php). Here, I am able to define application constants like a traditional PHP application.

define("GAL_THUMB_MAX_W", 120);

I think that I will use the constants.php file from now on.

Share

I’m learning Codeigniter for a project that I am working on. I ran into a problem when I created a controller method that accepts two parameters. My problem was that I did not know how to pass multiple paremeters using Codeigniter’s anchor function. The solution was quite simple in that all I had to do is add additional uri segments to the anchor function.

The controller method takes two arguments:

class Sites extends Controller {
     ...
     function updateVersion($vId, $sId) {
     ...
     }
}

Using the anchor function, I would then call this method that passes 2 as the $vId and 3 as the $sId (/2/3):

echo anchor('members/sites/updateVersion/2/3', 'select');

Simple enough.

Share