Eric Barnes

Eric Barnes

CodeIgniter, Development, Life, and Whatever else

Site Moved

Site Moved

Dec 06

I have moved this site. Please visit ericlbarnes.com for the new location.

CodeIgniter url_title

CodeIgniter url_title

Jul 12

The CodeIgniter url helper contains a very useful function named url_title(). This function is designed to take a string such as “my test string” and convert it to “my-test-string”. This works great for english characters but will/can fail when you throw in accented characters.

To get around this issue you will need to run the convert_accented_characters() on the string before passing it to the url_title. Here is a full example:

url_title(convert_accented_characters('My Café'));

I have seen several bug reports about this and to be honest I feel this is much more expressive than an alternative of:

url_title('My Café', 'dash', FALSE, TRUE); 

If you see the above code in a project can you tell what the FALSE and TRUE does? I even had to look up the function to find out what the current third param was. I had no idea it had a lowercase option. Which in my opinion is not even needed inside the function. Instead you should write it as:

strtolower(url_title('My Café', 'dash')); 

At the end of the day is writing two function calls that bad? It’s expressive, it does the job, and above all you get the same results.

CodeIgniter Security Basics

CodeIgniter Security Basics

Jun 27

By default CodeIgniter is a very secure framework and it also does a lot behind the scenes to help you out. I was recently contracted to look over a CodeIgniter application that was constantly getting hacked. So in light of what I seen I want to share some common pitfalls you need to avoid.

  1. Use Active Record! You should “almost” never write your queries manually.
  2. If you must write a query without active record be sure everything is escaped properly. $this->db->escape()
  3. Validate user input! CI has $this->input->post(), $this->input->get_post() and you should use those.
  4. Validate file uploads and use the upload library.
  5. Use the framework tools. It comes with tons of libraries and helpers that are designed to help you with common tasks. There is no reason to write your own if already accomplishes what you need.

Yes I know every php developer should know about these but some people still just haven’t gotten the memo. So spread the word, write secure apps, and make the world a better place.

How To: Contributing to a GitHub Project

How To: Contributing to a GitHub Project

Jun 17

This guide is Laravel specific but can be used as guide for any github project. If you have never contributed to a project then this is a great starting point.

PHPLighter - PHP Syntax Highlighting

PHPLighter - PHP Syntax Highlighting

Jun 17

A PHP syntax highlighting engine the utilizes token_get_all() to produce a level of syntax highlighting that rivals any modern editor. No more barebone generic syntax highlighting!

The indended purpose of this code is for sites that display a lot of code using basic syntax highlighting (Such as PasteBin) or programming blogs. There are lots of other uses for it though!

Looks like a really useful highlighting system if you are only going to be writing php code blocks.

JavaScript Profiling With Chrome

JavaScript Profiling With Chrome

Jun 13

This is a great introduction for profiling your javascript code using Chrome Developer Tools.

Real-world applications are much more complex than the example, but profiling them follows the same basic steps:

  1. Establish a baseline so that you know where you’re starting from.
  2. Isolate the problem from any other code running in the application.
  3. Make it faster in a controlled environment, with frequent timelines and profiles.

There are a few other rules to follow when tuning performance:

  1. Start with the slowest parts first so that you get the most improvement for the time spent tuning.
  2. Control the environment. If you switch computers or make any other major changes, always run a new baseline.
  3. Repeat the analysis to prevent anomalies on your computer from skewing the results.
Pigeon - elegant routing for CodeIgniter

Pigeon - elegant routing for CodeIgniter

Jun 12

Jamie Rumbelow created a new routing system for CodeIgniter named Pigeon. From what I have seen it looks great and will be really useful as more things are moving toward single page apps:

CodeIgniter’s routing engine is far too basic. Pigeon wraps around the core routing system to provide HTTP method based routing, RESTful resources and nested routes. It uses a natural DSL to make writing cleverer routes simple and elegant.

Here is an example of the routes:

Pigeon::map(function($r){
    $r->route('posts/(:num)', 'posts/show/$1');

    $r->get('posts', array( 'Posts', 'index' ));
    $r->post('posts', 'Posts#create' );
    $r->put('posts/(:num)', array( 'Posts', 'update' ));
    $r->delete('posts/(:num)', array( 'Posts', 'delete' ));

    $r->resources('posts');

    $r->resources('posts', function($r){
        $r->resources('comments');
    });
});

$route = Pigeon::draw();
Atlanta PHP Meetup

Atlanta PHP Meetup

Jun 09

Atlanta Skyline

I had the pleasure of attending the Atlanta PHP’s meetup on Thursday at StrongBox West where Ben Edmunds gave a talk about the Laravel framework.

Doug Grubba and I decided to carpool down since Atlanta1 is about 4 hours from Charlotte. I will be totally honest I really didn’t have high hopes on how the meetup would go. I have been to some local meetups and I was just not that impressed. Low turnout, weird locations, etc. But Chris Spruck and the ATL guys are top notch. They had a lot of great sponsors, food provided, free prizes, and above all a nice turn out. (I estimated about 50 people).

After the meeting a few of us went over to local pizza shop and talked about all sorts of web topics and where our next stop in hotlanta should be.2

I had a wonderful time and wished I lived closer so I could attend more of their meetups. They get two thumbs up from me and hopefully I will get to visit again.


  1. Photo by tableatny 

  2. Ended up going back to the hotel and watching some gator hunting. But hey my wife is happy about that. :) 

ericbarnes Jun 06

LeakedIn

LeakedIn

Jun 06

Nice way to test if your linkedin password is one that was cracked. I closed my account a month or so ago and it appears mine was on the list. So I guess I need to be in the support group and be sad that even though I closed my account they didn’t remove my data. Which I bet is common practice.

Page 1 of 15 1 2 3 4 5