Tag: web development

Pesky Directory Alphabet Filters Made Easy (PHP)

I have built quite a few directory systems in my years as a web developer and one thing that has always annoyed me is building letter filters to return results depending on the first letter of a title.

Normally I would waste a lot of time actually typing out the entire alphabet string:

$alphabet = 'abcdefghijklmnopqrstuvwxyz';

which can take a lot of time (Go on try it, I’ll bet no matter how fast you can type, typing out the alphabet quickly will be tricky!) then looping through the string like so:

for($i = 0; $i < strlen($alphabet); $i++)
{
  echo substr($alphabet, $i, 1);
} 

However there are 2 other much simpler methods:

Method 1 – Loop through the ASCII numbers

for($i = 65; $i <= 90; $i++)
{
  echo chr($i);
}

or my new personal favourite using PHP’s range() function:

Method 2 – Using range()

foreach(range('A', 'Z') as $i)
{
  echo $i;
}

Then all you have to do is add in any code to make sure you set the right CSS selectors and highlight which letter you are currently viewing and add the ability to filter by first letter to your list function.

Simple.

Why do IT Pros have so much free time?

Why do IT Pros seem to have so much free time?

Why do IT Pros seem to have so much free time?

eviljaymz.com

Get your PHP on the right Trax

Original Article on The Register

Hands on Ruby on Rails has become a popular framework for developing database-based web applications using the Model-View-Controller (MVC) pattern.

Before Ruby on Rails, though, PHP was hogging the web-development limelight. Problem was, there was no Model-View-Controller (MVC) framework for PHP.

With Ruby on Rails, though, PHP developers have come to realize the timesaving benefits of MVC – a fact that led to the development of various PHP frameworks that are actually based on Ruby on Rails.

Among them, the Akelos framework and PHP On Trax.

In this article we shall develop an MVC Create-Read-Update-Delete (CRUD) application using the PHP On Trax Framework. Why this particular framework? Simple: it is a direct port of the Ruby on Rails framework.

I haven’t managed to try this out yet but it I didn’t see anything in it that would’t be able to be set up in a linux environment, The article goes into a fair amount of detail (3 pages) in how to get it working. If anyone has had a go at this let me know how you have got on, I don’t really have the time at the moment!