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 ‘PHP’

I’m redesigning my portfolio site and decided to use Joomla. I just installed it on my Ubuntu box. It wasn’t difficult, but it could have been easier.

First I downloaded Joomla from here. I had the option of download a nightly build, but I wanted the latest stable version.

Read the rest of this entry »

I have been upgrading an web application for a client. I initially created the application using a custom php framework – spliced together however awkwardly, but it worked. In version 2, I included YUI 2.8, but have been using the same backend.

The site is nearly complete (ajax functionality, and database development), I decided that I needed a more structured php framework. I chose CakePHP primarily because I could bake the models, views, and controllers. With only 17 tables, The application is not very large, but the thought of creating models, views, and controllers for 17 tables did not sound exciting.

I could not bake on my Mac. I got an error, “Call to undefined function mysql_connect()”. I searched for hours trying to figure out why I was receiving the error, but to no avail. I think that I need to re-install PHP. Not going to happen. I instead decided to setup Cake on my Ubuntu box (See my post: Setting Ubuntu For Web Development).

Read the rest of this entry »

I’ve developed in the Windows environment for most of my career.  About 4-5 years ago I began to migrate to the Mac. Now my Mac is my primary computer.

I recently worked on a project where the target OS is linux, so I installed Ubuntu 9.04 desktop on an old PC. The following are the steps I took to create a web development box. This post assumes that you have already installed Ubuntu. Click here or here for installation instructions.

After you have installed ubuntu, you may want to select/download a theme for your box. Click Install Instructions to learn how to install gnome themes.

First, I will set up LAMP (Linux, Apache, MySQL, PHP) and phpMyAdmin. AMP is my default web development environment, regardless of OS.

Next, I will install Python, Django, PostgreSQL, phppgadmin, and pgAdmin (needed for my new project).  I will also install Aptana Studio and Java (need JRE to run Aptana). I have been using Aptana Studio on my Mac for over a year, and it has become my default development IDE.

Read the rest of this entry »

I just ran into a problem when I was attempting to pass a PHP POST variable that contained a period. I’m not sure why I have never run into this situation in the past. PHP will automatically convert a period into an underscore. I submitted a form  with a field with the name ‘co.uk’. I then checked for the existence of the post variable in a PHP class (if  $_POST['co.uk']). It did not exist. I then checked (if $_POST['co_uk']) and was able to get the value. Interesting.

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 »

PHP, mac

A few days ago, I was testing a PHP class I created that uploads images and creates thumbnails. I ran into an error when I called imagecreatefromjpeg. phpInfo() revealed that the GD Library was not installed on my Mac G5. All the sites I visited said that I would have to recompile PHP with GD support enabled. I considered working on my PC rather than recompiling PHP, but my Mac has become my primary development box, so I knew that I would need the GD Library for future projects.

Initially, I considered a new entropy PHP package. I used the entropy version a few years ago, but I ran into problems after I installed Leopard. I was fairly confident that entropy would now “play nice” with Leopard, but I wasn’t sure what it would do to my existing MySQL database.

I then considered using MacPorts to install PHP, but decided against it, because I wanted to use my existing infrastructure, not a re-installation of everything (Apache, PHP, and MySQL). If you haven’t yet started any development on your Mac, then I recommend that you use the MacPorts package. I found great instructions here.

So I made the decision to just recompile PHP with GD Support. After a few hours, I began to think that this was not a good decision. I was following the step-by-step instructions that I found here.

First I had to download and install a new version of Xcode because during one of the steps, I received the error, “C compiler cannot create executables”. Although Xcode was already installed on my Mac, it was an older version.

I then received an error when I tried to compile the GD Library (under the section: Download and Compile GD Graphics Library extension). The error was due to the t1lib not being installed. I recommend that you do a search for the t1lib after you install Xcode. If it is not present, you can go here for download/installation instructions.

One of the last steps involves confirming that PHP is loading the gd.so extension.

/usr/bin/php -i|grep -i gd

I received the error:

PHP Warning:  PHP Startup:
Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20060613/gd.so'
- (null) in Unknown on line 0

I simply copied the gd.so file from /SourceCache/php-5.2.8/ext/gd/ to /usr/lib/php/extensions/no-debug-non-zts-20060613/. I then received the confirmation:

gd
GD Support => enabled
GD Version => bundled (2.0.34 compatible)

Additional Notes

1. Under the section, “Download and compile the GD graphics library extension”, the step refers to php 5.2.6. I changed it to php 5.2.8. Actually, I opened my browser and navigated to: http://opensource.apple.com/. I then selected the version of Mac OS X that I am using (10.5.7). I then scrolled down the list and selected apache_mod_php-44.2 and found php-5.2.8.tar.bz2. So my curl statement was:

curl -O http://www.opensource.apple.com/darwinsource/10.5.7/
apache_mod_php-44.2/php-5.2.8.tar.bz2

2. A few of the steps require you to type:

make install

You really have to type:

sudo make install

or you will receive an error. Enter your password as required.

While recompiling PHP with GD support is not for the faint of heart, it can be done. Now I can get back to work.

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

PHP

I am working on an image upload plugin that uses JQuery. I am using PHP on the backend. I have found that there are multiple ways to use PHP to get the file extension of an image.

PathInfo

PathInfo is probably the most common way get information about a file.

$path_parts = pathinfo('http://grasshopperpebbles.com/photogallery/thumbs/pic1.png');
echo $path_parts['dirname']; //output: http://grasshopperpebbles.com
echo $path_parts['basename']; //output: pic1.png
echo $path_parts['extension']; //output: png
echo $path_parts['filename']; //output: pic1

GetImageSize

Although I have used PHP’s getimagesize to get the dimensions of an image, it can also be used to get other information (to include the file type):

list($width, $height, $type) = getimagesize('pic1.png');
echo $type; //output: png

End

Recently, I stumbled upon a new way to get the file extension:

$file_name = current(explode('.', 'pic1.png'));
$ext = end(explode('.', 'pic1.png'));
echo $file_name; //output: pic1
echo $ext; //output: png

I’m sure there are other ways to use PHP to get the file type as well.

I have been a PHP developer for many years and I have recently started learning Drupal 6. I struggled for a few days just trying to modify one of the existing themes. If any of you are just starting to learn Drupal and you want to create your own design/theme, I found that the easiest way is to first create your design template (HTML and CSS) without the PHP/Drupal code. Once your design is complete and can be viewed correctly in the modern browsers, then  open up one the themes (page.tpl.php) that are installed with Drupal and copy/paste the revelant PHP code into your template. I also use this approach when I create Wordpress themes.

Before you begin your design, make sure that you have a fairly good understanding of Drupal’s Regions, Blocks and Modules and Blocks (Blocks are placed into Regions). Namely, header, left side, right side, and footer. You don’t necessarily have to use all regions in your design (i.e., you may not need a right side), but you should have a good understanding of what each region can be used for.

When I created my first Drupal theme, I did not think that I needed a right side, so I did not create one. But after I looked at other websites that use Drupal (and the many contributed modules), I found some very good content ideas that can be placed on the right side of my Drupal theme template.

I will, from time-to-time, post other Drupal tidbits (as I learn them).