mrforbes design - a web design and development studio

Blog - One Byte at a Time

Technology moves fast. Its hard to keep up. By the time you've mastered one tool, another has come along to replace it. You can't catch up, so just take it one byte at a time.

My Windows Vista Rant

May 28th, 2007

I’m sure everyone who has used Vista has at least one. The things about it that make you just want to pull your hair out. It could be the User Access Controls (I turned it off as soon as I installed Vista - I couldn’t download my Quicken data with it turned on, in fact it never even offered to LET me download it). It could be the fact that file transfer/addition/deletion time is directly proportional to the NUMBER of files, rather than the SIZE of the files (huh?).

For me.. its Vista and its interaction with Adobe Photoshop, CS3 edition.

My computer isn’t THAT slow. Its a Pentium D 820, with 1GB (too little for Vista BTW) RAM, and 320GB worth of HDD space in a RAID 0 configuration. I have a GeForce 7800 video card so Aero shouldn’t be an issue. Yes, the computer is nearly two years old, but I’m quite sure the issue is not with the parts. You see - opening a file in Photoshop for me is a ’sit and have a cup of coffee in the meantime process’. Opening a file takes a good five to ten seconds. That would be fine if I were referring to a 300ppi 8×10 page layout, or something of the ilk. But I’m not. My reference is a 12k .png. No, that isn’t a typo. 12k.

You can imagine my frustration when I’m creating small buttons, and each time I open one I have to wait 5-10 seconds for it to actually appear on the screen, at which point Photoshop acts like its on its last breath. I have the same problem when I create a new document. It doesn’t matter how big or small it is, I sit and wait. Why?

I suppose I should be grateful - after all, I used to only sip on my coffee once in awhile, and it would last a good 4 hours to go through a cup. Now, I take a small sample at each file load, and I’m going through a few cups a day. I’ve got more energy. My skin is looking a little better, and I’m losing weight (caffeine is an appetite suppressant).

Ok, I’ve reconsidered. Here’s to you Windows Vista - for giving me more time for coffee.

Site Tags:
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...
Posted in Software, Vista | 1 Comment »

Eclipse

May 21st, 2007

I recently began to wonder if there was an IDE out there that would suit my style of development better than Dreamweaver. As a result, I began scouring the internet for reviews and information on other PHP environments, which would hopefully speed up my development process. After trying such applications as Komodo and Zend Studio, I decided to check out Eclipse. I had looked into Eclipse almost a year ago, and had never actually installed it. It seemed daunting to me at the time, though I can no longer remember why. In actuality, the installation and transition has been smooth.

Installation
To install, first go to http://java.sun.com/javase/downloads/index.jsp and download the Java Runtime Environment. Eclipse is a Java application. Then, head over to http://www.eclipse.org to download the latest Eclipse version.

Once you’ve done that, you can visit http://www.zend.com/de/pdt to get Zen’s PHP IDE for Eclipse. With that, you’ll get quick reference to PHP functions, PHP code completion, and the possibility to get local debugging installed. This part was a little tricky though, as i had to download the full PDT version to get some of the required libraries (just copy this plugin directory to the plugin directory of the Eclipse you downloaded from eclipse.org). Not too bad though.

The best part of installing Eclipse, is that you don’t actually install Eclipse. Once you unzip it, and copy over the plugins folder from the PDT version on Zend.com, double-click the .exe and you’re up and running. Adding plugins to Eclipse is easy too - follow the instructions for updating on the Zend site and you’ll be able to add anything, because the method is the same - only the links will change.

Add-ons
Beyond the PHP IDE (if you use PHP) - get a hold of Aptana, a Javascript/HTML/CSS IDE for Eclipse. It also comes with an FTP tool, though it is a little basic. It won’t do the ‘upload to server on save’ action that Dreamweaver will, but you can right-click a file and select synchronize to upload. This minor negative hardly outweighs the benefits.

There are two more things you’ll probably want to download for Eclipse - a plugin to allow virtual word wrapping (no, word wrapping is not available by default - there’s a good explanation out there if you google it). Here’s the link. Also, an application so you can view images in folder’s within the eclipse structure. This just makes it easier to upload images through the Eclipse FTP, instead of having to use a separate program (though you WILL need one to do things like change folder permissions). You can get one here.

Features
I’ve been using Dreamweaver for years, and Homesite before that. Moving to Eclipse was relatively painless, because of the areas where it outshines Dreamweaver.

  1. Price
    It’s free, the PHP IDE is free, Aptana is free. You can’t beat that.
  2. Function Reference and Folding
    I don’t mean referring to PHP or Javascript functions (though it provides that also). Instead, I’m talking about the window on the right side that shows all of your functions and classes, so you can find the one you need quickly and easily. Default code folding also assists in speeding up location times.
  3. Highlighting
    Eclipse highlights the line of text you are currently editing. This may not seem like much, but I find it very handy.
  4. Code Completion / Class Reference
    Did you write your own class, want to reference it, but can’t remember the parameters? Just leave your mouse over the function call and it will show you.
  5. Proper Indenting
    I always fought with DW to get it to tab-indent properly. Not only does Eclipse do it automatically when you open a curly brace, but it indents properly nearly all of the time.
  6. Performance
    Dreamweaver also seemed a bit bloated to me - perhaps it was all the WYSYWIG stuff that I never used… In any case, Eclipse is much quicker, though it does love to use your memory - generally about 200mb.

I’ve been using Eclipse for about a week now, and I would recommend anyone to give it a shot. It may not be for everyone, but its certainly made me a more efficient programmer.

Site Tags:
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...
Posted in PHP, Software | No Comments »

Manually Add Customers to Zen Cart

May 15th, 2007

If you are a Zen Cart developer, there may come a time in your life that a client has a need to be able to add customers to the application themselves, rather than waiting for customers to come and create an account. This is functionality that is not directly built into the Zen Cart application, and as such, requires a third party plugin.

I had a need for such a plugin, and finding it didn’t already exist, created it myself. If you have the need, you can download it at the Zen Cart site through the link below:

Zen Cart: Manually add customers through the admin

Site Tags:
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...
Posted in PHP, Zen Cart | No Comments »

A Quick Code Igniter and JQuery Ajax Tutorial

May 13th, 2007

This tutorial assumes a basic working knowledge of Code Igniter. If you have never used CI before, please refer to the framework documentation

In the old days (2 years ago), working the Javascript magic to create a cool AJAX based event took a fairly decent working knowledge of the mechanisms behind the process. With the increasing popularity of Javascript libraries however, this type of functionality became available to the web site hobbyist, and was made much easier for the web site professional.

The following step-by-step tutorial will show you how to combine the power of JQuery (a javascript library that weighs in at about 20k) with Code Igniter (a PHP framework based on the MVC design pattern) to quickly and painlessly pass a record ID through the javascript and over to the server, where it will be passed to a mysql database, used to retrieve some data, and sent back to the page for display.

Step 1
We begin by assuming that you have a div with an id of content, which is where you would like your freshly retrieved data to display, once it has been freshly retrieved. For this exercise, you have already taken an action to call your javascript function with a record ID parameter.

The first thing you need to do, is make sure JQuery is being loaded, and to create a function for your AJAX request.

  1. <script language="javascript" src="/path_to_jquery/jquery.js" ></script>
  2. <script function get_record_id(record_id)
  3.      {
  4.      }
  5. </script>
  6. </script>

Step 2:
Next, youll use the JQuery function load, and attach it to your content div:

  1. function get_record_id(record_id) {
  2.      $(‘#content’).load()
  3. }

Step 3:
The load function accepts three arguments. The page to be called on the other side of the HTTPRequest, the array to pass through the POST, and a callback function. It looks like this:

  1. function get_record_id(record_id) {
  2.      $(‘#content’).load(/controller/method,p,function(str){
  3.      
  4.          });
  5. }

Lets go back to that. Code Igniter URLs are created by calling the name of your controller, followed by the function inside the controller class that will handle your request. If your server does not support mod-rewrite, you may also need to append an index.php to the beginning. The str inside the callback function is the results of your AJAX request. There isnt much use for the str when using the .load function, but it does come in handy using the other JQuery AJAX functions - $.post and $.get, which I assume are self explanatory.

Step 4

  1. var p = {}; //instantiate the array
  2. p[record_id] = record_id //assign your record_id variable to it.

Thats all there is to it. Your final javascript function looks like this:

  1. function get_record_id(record_id) {
  2.      var p = {};
  3.      p[record_id] = record_id
  4.      $(‘#content’).load(/controller/method,p,function(str){
  5.  
  6.      });
  7. }

Step 5
On the CI side, you have a controller and method setup something like this:

  1. class Controller
  2. {
  3.    function Controller()
  4.    {
  5.        parent::CI;
  6.    }
  7.    
  8.    function method()
  9.    {
  10.    }
  11. }

The important part is the method() function, as it will contain some of the code we need to make things happen.

Step 6
The first thing you need to do on the CI side is retrieve the value passed through the request object. This is simple enough, using $_POST[record_id]. You also want to load up your database model so you can get the record out of your database. So, well load the database library, and then load the actual model. Then, we want to send the record ID to the database, get the resulting data, and pass it back out to the request. our function starts to look like its doing something useful pretty quickly.

  1. function method()
  2. {
  3.    $record_id = $_POST[record_id]//set the record ID
  4.    $this->load->library(database); //load the database library to connect to your database
  5.    $this->load->model(records); //inside your system/application/models folder, create a model based on the procedure outlined in the CI documentation
  6.    $results = $this->records->get_record($record_id); //get the record from the database
  7. }

Step 7
At this point, we need to go into our records.php file in the model folder. Since Code Igniter uses a Model-View-Controller structure, database activity, server-side processing, and client-side display should be as separate from one another as possible. You dont NEED to do this for Code Igniter to do its thing, but its good practice.

Inside the records.php file, well create a method called get_record to match the method referenced above. Well use it to get a record by its primary key of ID, put the resulting data into an array, and send it back to the controller, out to the view, and ultimately into the content div we started with.

  1. function get_record($record_id)
  2. {
  3.    $this->db->where(ID,$record_id); //we want the row whose ID matches the value were passing in
  4.    $query = $this->db->get(record_table); //get the table and put it into an object named $query
  5.    $row = $query->row(); //gets the first row of the resulting dataset.  In this case, only 1 row will ever be returned
  6.    $results[record][$row->ID][name] = $row->name; //here, we create a multi-dimensional array holding the returned values based on the key. 
  7.    return $results; //send the record back to the controller
  8. }

The trickiest part of this section is the array. It seems pretty complex from here, but youll see soon enough how it breaks down into something more manageable as we go along.

Step 8
Were back to the controller again, and we have one more line to add - this time to pass the resulting data into a view to be formatted and printed to the content div. The whole method() function now looks like this:

  1. function method()
  2. {
  3.    $ID = $_POST[record_id]//set the record ID
  4.    $this->load->library(database); //load the database library to connect to your database
  5.    $this->load->model(records); //inside your system/application/models folder, create a model based on the procedure outlined in the CI documentation
  6.    $results = $this->records->get_record($record_id); //get the record from the database
  7.    $this->load->view(AJAX_record,$results);
  8. }

Step 9
The AJAX_record.php file should be in your system/application/views folder. Keep in mind, that when you pass an array to a view (in this case the $results array), it will be exploded inside the view. So, the path to your record is now $record, instead of $results[record]. Also inside will be your standard HTML markup, and something like this:

  1. < ?php foreach($record as $id=>$value) { ?>
  2.      The name associated with this record is: < ?php print $value[name];?>
  3. < ?php } ?>

This output is what php is sending to the request object, and is also what gets loaded into the content div. Code Igniter and JQuery make it that easy to dynamically load data using AJAX.

Site Tags:
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...
Posted in Ajax, Code Igniter, Jquery, PHP, Tutorials | 15 Comments »