Administration Generation

January 31st, 2010

Ever since I have started programming with PHP, the most repetitive and unchallenging task I have had to do is to write code for administration control panels. Every project I make needs one, and a good one at that, so that it is easy for my clients to manage their websites, without needing my help (which saves them both time and money), but it gets repetitive.

The problem

Let us say for example that we want to create a small personal website, where the owner can post news articles. I need to write the code for the administration control panel (bearing in mind that the admin needs a login to stop unauthorized access). That implies coding at the very least a login page, logout, and a basic dashboard. Afterwards, it is necessary for me to write code to manage/view/create/edit/delete news articles. So far, it’s simple. Six months later, the owner e-mails me telling me that his website became very popular, and he wants to enable comments on his news articles. He also wants people to sign up for a newsletter and the ability to write newsletters from the administration control panel (and keep a record of the ones that he already sent). Now, the administration panel has to have a page to manage/view/edit/delete comments, and it has to have a page to manage/view/edit/delete users. It also has to have a page to manage/view/create newsletters. Suddenly, that simple administration panel is now a bit more complex. Granted, this is still not a big problem. However, not all websites are that simple. Some websites can have far more tables, and be far more complex than the simple personal website illustrated in this example. Additionally, it consumes a large amount of time, especially on the more complex websites. After countless times of doing this for every project, I decided that I had to write something to generate the administration panel’s code for me.

The solution – Terra Duo Admin

As soon as I had the free time, I started writing a controller class to generate manage/view/create/edit/delete pages on demand, designed to be as simple as possible. My theory was that the simpler it was to implement this on a new or existing project, the more efficient it would be. For that purpose, I started by writing the code that I wanted to have in order to generate the pages, and I came up with the following:

$Admin->setTableConfigs($tableConfigsArray); # This would contain an array describing the table’s name, the table’s fields, along with their validation rules and any other settings necessary to administer a table.

$Admin->Create();

$Admin->Edit($ID);

$Admin->Delete($ID);

$Admin->View($ID);

$Admin->Manage($Page, $RowsPerPage);

I felt that that was the only code that was necessary to write for any administration control panel, on any project. It keeps it as simple as it can possibly be, and it would allow me to spend more time working on the frontend (which is what really matters, since that is what the end-users see). I could go to my CodeIgniter admin controller and dump this code there, to get admin/create, admin/edit, admin/delete, etc working, and have myself a nice administration control panel. I knew about Symphony’s Admin Generator, but the fact that it was only for Symphony was one of the reasons why I did not want to use it. The other was simply that I wanted to abstract away as much as possible, and leave it with the least amount of configuration necessary. I also didn’t want it to generate physical code files, because I would then have to deal with updating them whenever I updated the database structure. I wanted something that would just work, based on the table configurations array I gave it, so that if for example, I was in the manage users section, I would give it the configurations for the users table, and if I was in the manage news posts section, I would give the configurations for the news table, and so on. After that, it would generate the requested page, for the given table. I also wanted it to be able to work on its own.

There were several challenges to this approach. Firstly, to deal with user login in a way that would work with the project’s existing user system. Secondly, to validate all the input (for that, I used my Table Manager, which gives me a simple approach for generating and executing SQL to manage database tables and supports validation so that no data can be selected, inserted or updated in the database without it being validated and sanitized first – I will be posting this soon). My third goal was to make it beautiful, easy to use, fast, and with as many advanced features as possible (for example, filtering results, creating/editing/deleting with ajax when available, among others), so that the end result was actually better than most administration control panels I’ve ever seen or made.

I will follow up on this post later this week with another post for the release of a 1.0 release. I will spend this final week finishing some important features that I need for the 1.0 and working out the kinks.

Terra Duo, after a month.

January 10th, 2010

After pushing myself to launch my website on the 11th of December, I expected to keep working on it, as there are a number of new features I would like to add to it (including a place to host my personal projects). I also expected to start posting on my blog straight after the launch date, and write articles that would be interesting to a vast number of people, and that would be helpful to those in the website development community. However, this was not to happen. My clients’ projects took over, and my free time was very limited.

Today, I was in the middle of building an AIR application for my latest project, Staff Guardian, and I found it difficult to access documentation on some of the things I wanted to do with the application. This led me to think that if I posted on my blog every time I solve a new problem, or simply learn something new about website development, I could help the website development community, by providing them with something worth reading. Real solutions to real problems. And, of course, I am not going to be talking about things on which there is a vast amount of documentation, as I feel that there is no point in writing an article about what has been said over and over again in other articles. I simply want to make this a great blog, with great articles. It’s my first time writing a website development blog (shocking, I know), so this will also be my place to learn about what makes a great blog great.

Hopefully, 2010 will be a great year. I know it’s already the 10th, but I would like to wish you a Happy New Year nonetheless. Expect to see more posts of me from now on, and hopefully they won’t be too boring. ;)

Terra Duo is finally running.

December 11th, 2009

Hold on tight, I’m still working on some of the features; I’ll start posting on this blog as soon as possible :-)